Skip to content

Commit d09a7cc

Browse files
committed
gh-131798: Narrow the return type of _FORMAT_SIMPLE and _FORMAT_WITH_SPEC to str for built-in types
1 parent ed1204e commit d09a7cc

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Python/optimizer_symbols.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ _Py_uop_sym_get_const_as_stackref(JitOptContext *ctx, JitOptRef sym)
264264
return PyStackRef_FromPyObjectBorrow(const_val);
265265
}
266266

267+
static bool
268+
is_safe_builtin_type(PyTypeObject *typ)
269+
{
270+
return (typ == &PyUnicode_Type) ||
271+
(typ == &PyFloat_Type) ||
272+
(typ == &_PyNone_Type) ||
273+
(typ == &PyBool_Type) ||
274+
(typ == &PyFrozenDict_Type);
275+
}
276+
267277
/*
268278
Indicates whether the type is a known built-in type
269279
that is safe to narrow.
@@ -275,12 +285,7 @@ _Py_uop_sym_is_safe_type(JitOptRef sym)
275285
if (typ == NULL) {
276286
return false;
277287
}
278-
return (typ == &PyLong_Type) ||
279-
(typ == &PyUnicode_Type) ||
280-
(typ == &PyFloat_Type) ||
281-
(typ == &_PyNone_Type) ||
282-
(typ == &PyBool_Type) ||
283-
(typ == &PyFrozenDict_Type);
288+
return (typ == &PyLong_Type) || is_safe_builtin_type(typ);
284289
}
285290

286291
/*
@@ -298,11 +303,7 @@ _Py_uop_sym_is_safe_const(JitOptContext *ctx, JitOptRef sym)
298303
return true;
299304
}
300305
PyTypeObject *typ = Py_TYPE(const_val);
301-
return (typ == &PyUnicode_Type) ||
302-
(typ == &PyFloat_Type) ||
303-
(typ == &_PyNone_Type) ||
304-
(typ == &PyBool_Type) ||
305-
(typ == &PyFrozenDict_Type);
306+
return is_safe_builtin_type(typ);
306307
}
307308

308309
void

0 commit comments

Comments
 (0)