https://github.com/python/cpython/commit/a92aec101e6e58a784d92f80ee232e4527c3e067
commit: a92aec101e6e58a784d92f80ee232e4527c3e067
branch: main
author: Petr Viktorin <[email protected]>
committer: encukou <[email protected]>
date: 2025-09-09T14:57:07+02:00
summary:
gh-133143: Use _Py_ID for the other literals in sys (GH-138698)
Follow-up refactoring after GH-133143, where we use `_Py_ID` for "big" and
"little"
in `abi_info.byteorder`.
This uses `_Py_ID` for `sys.byteorder`, but also `float_repr_style` and a
module name.
files:
M Include/internal/pycore_global_objects_fini_generated.h
M Include/internal/pycore_global_strings.h
M Include/internal/pycore_runtime_init_generated.h
M Include/internal/pycore_unicodeobject_generated.h
M Python/sysmodule.c
diff --git a/Include/internal/pycore_global_objects_fini_generated.h
b/Include/internal/pycore_global_objects_fini_generated.h
index ad65d1fda18e3b..63888eab7b4481 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -1080,6 +1080,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(last_value));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(latin1));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(leaf_size));
+ _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(legacy));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(len));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(length));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(level));
@@ -1253,6 +1254,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(setstate));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(shape));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(shared));
+ _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(short));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(show_cmd));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(signed));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(signum));
diff --git a/Include/internal/pycore_global_strings.h
b/Include/internal/pycore_global_strings.h
index 88283fa625706f..b863a7c970e3d4 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -571,6 +571,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(last_value)
STRUCT_FOR_ID(latin1)
STRUCT_FOR_ID(leaf_size)
+ STRUCT_FOR_ID(legacy)
STRUCT_FOR_ID(len)
STRUCT_FOR_ID(length)
STRUCT_FOR_ID(level)
@@ -744,6 +745,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(setstate)
STRUCT_FOR_ID(shape)
STRUCT_FOR_ID(shared)
+ STRUCT_FOR_ID(short)
STRUCT_FOR_ID(show_cmd)
STRUCT_FOR_ID(signed)
STRUCT_FOR_ID(signum)
diff --git a/Include/internal/pycore_runtime_init_generated.h
b/Include/internal/pycore_runtime_init_generated.h
index a08d77ab0a06b9..3ce7200ffeb6a4 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -1078,6 +1078,7 @@ extern "C" {
INIT_ID(last_value), \
INIT_ID(latin1), \
INIT_ID(leaf_size), \
+ INIT_ID(legacy), \
INIT_ID(len), \
INIT_ID(length), \
INIT_ID(level), \
@@ -1251,6 +1252,7 @@ extern "C" {
INIT_ID(setstate), \
INIT_ID(shape), \
INIT_ID(shared), \
+ INIT_ID(short), \
INIT_ID(show_cmd), \
INIT_ID(signed), \
INIT_ID(signum), \
diff --git a/Include/internal/pycore_unicodeobject_generated.h
b/Include/internal/pycore_unicodeobject_generated.h
index 57c0a7d51f89f3..e76e603230a5db 100644
--- a/Include/internal/pycore_unicodeobject_generated.h
+++ b/Include/internal/pycore_unicodeobject_generated.h
@@ -2072,6 +2072,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp)
{
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
assert(PyUnicode_GET_LENGTH(string) != 1);
+ string = &_Py_ID(legacy);
+ _PyUnicode_InternStatic(interp, &string);
+ assert(_PyUnicode_CheckConsistency(string, 1));
+ assert(PyUnicode_GET_LENGTH(string) != 1);
string = &_Py_ID(len);
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
@@ -2764,6 +2768,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp)
{
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
assert(PyUnicode_GET_LENGTH(string) != 1);
+ string = &_Py_ID(short);
+ _PyUnicode_InternStatic(interp, &string);
+ assert(_PyUnicode_CheckConsistency(string, 1));
+ assert(PyUnicode_GET_LENGTH(string) != 1);
string = &_Py_ID(show_cmd);
_PyUnicode_InternStatic(interp, &string);
assert(_PyUnicode_CheckConsistency(string, 1));
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index a5b42d48e432d7..832d2afff806ab 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -610,7 +610,7 @@ sys_breakpointhook(PyObject *self, PyObject *const *args,
Py_ssize_t nargs, PyOb
if (last_dot == NULL) {
/* The breakpoint is a built-in, e.g. PYTHONBREAKPOINT=int */
- modulepath = PyUnicode_FromString("builtins");
+ modulepath = &_Py_ID(builtins);
attrname = envar;
}
else if (last_dot != envar) {
@@ -3873,9 +3873,9 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS("builtin_module_names", list_builtin_module_names());
SET_SYS("stdlib_module_names", list_stdlib_module_names());
#if PY_BIG_ENDIAN
- SET_SYS_FROM_STRING("byteorder", "big");
+ SET_SYS("byteorder", &_Py_ID(big));
#else
- SET_SYS_FROM_STRING("byteorder", "little");
+ SET_SYS("byteorder", &_Py_ID(little));
#endif
#ifdef MS_COREDLL
@@ -3917,9 +3917,9 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
#if _PY_SHORT_FLOAT_REPR == 1
- SET_SYS_FROM_STRING("float_repr_style", "short");
+ SET_SYS("float_repr_style", &_Py_ID(short));
#else
- SET_SYS_FROM_STRING("float_repr_style", "legacy");
+ SET_SYS("float_repr_style", &_Py_ID(legacy));
#endif
SET_SYS("thread_info", PyThread_GetInfo());
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]