Skip to content

gh-133644: remove deprecated global configuration variables #133654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented May 8, 2025

Ok, this one is really tricky and I really need more eyes to be sure about it, namely @vstinner's eyes.

There are two global configuration variables that were marked as deprecated but not explicitly slated for removal in the docs, namely Py_UTF8Mode and Py_InteractiveFlag. As such, I've left them untouched. They were however mentioned in the "pending removals" documents so I don't know if we can just remove them (note that users are more likely to land on the C API page rather than the what's new page when they are looking for docs).

I'll write a NEWS entry afterwards.


📚 Documentation preview 📚: https://cpython-previews--133654.org.readthedocs.build/

@picnixz
Copy link
Member Author

picnixz commented May 8, 2025

I may have held the GIL for too long on Windows builds or something like that. Will investigate.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is wrong. You cannot simply remove symbols from the stable ABI. Instead, you should only move variables declaration from the public C API to the internal C API. Also, you should keep tests on these variables whenever possible.

@picnixz
Copy link
Member Author

picnixz commented May 8, 2025

You cannot simply remove symbols from the stable ABI

Yeah, I actually wondered whether they were stable or not but apparently they are :') I only thought about this when I wrote the other PRs...

However, this makes my life much easier then!

@vstinner
Copy link
Member

vstinner commented May 8, 2025

UPDATE: I added matching lines and I ignored Pillow which is up to date.

A code search on PyPI top 8,000 projects finds matchs in 20 projects:

  • Nuitka (2.6)
  • SimpleParse (2.2.4)
  • catboost (1.2.7)
  • cffi (1.17.1)
  • cx_freeze (7.2.8)
  • cython (3.0.11)
  • hunspell (0.5.5)
  • lmdb (1.6.2)
  • mpi4py (4.0.1)
  • nanobind (2.4.0)
  • numpy (2.2.2)
  • orjson (3.10.15)
  • pygame (2.6.1)
  • pygit2 (1.17.0)
  • pythonnet (3.0.5)
  • pyuwsgi-2.0.28.post1
  • rook (0.1.209)
  • scandir (1.10.0)
  • subprocess32 (3.5.4)
  • uwsgi (2.0.28)
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/deprecated/python/scandir/_scandir.c: // Because on PyPy, Py_FileSystemDefaultEncoding is (was) defined to be NULL
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/deprecated/python/scandir/_scandir.c: #define FS_ENCODING (Py_FileSystemDefaultEncoding ? Py_FileSystemDefaultEncoding : "UTF-8")
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/deprecated/python/subprocess32/_posixsubprocess_helpers.c: if (Py_FileSystemDefaultEncoding)
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/deprecated/python/subprocess32/_posixsubprocess_helpers.c: Py_FileSystemDefaultEncoding,
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/deprecated/python/win-unicode-console/win_unicode_console/runner.py: inspect_flag = cast(pythonapi.Py_InspectFlag, POINTER(c_long)).contents
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/python/numpy/py2/numpy/core/src/multiarray/compiled_base.c: if (Py_OptimizeFlag > 1) {
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/python/numpy/py3/numpy/core/src/multiarray/compiled_base.c: if (Py_OptimizeFlag > 1) {
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/python/numpy/py3/numpy/core/tests/test_numerictypes.py: reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1")
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/python/numpy/py3/numpy/ma/tests/test_core.py: reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1")
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/python/numpy/py3/numpy/random/tests/test_direct.py: # no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/python/numpy/py3/numpy/random/tests/test_extending.py: # no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/tools/cython/Cython/Utility/Exceptions.c: #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/tools/cython/Cython/Utility/Exceptions.c: #define __pyx_assertions_enabled() (!Py_OptimizeFlag)
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/tools/cython/Cython/Utility/Exceptions.c: // Py_OptimizeFlag is deprecated in Py3.12+
catboost-1.2.7.tar.gz: catboost-1.2.7/catboost_all_src/contrib/tools/cython/Cython/Utility/Exceptions.c: #define __pyx_assertions_enabled() (!Py_OptimizeFlag)
cffi-1.17.1.tar.gz: cffi-1.17.1/src/c/_cffi_backend.c: Py_FileSystemDefaultEncoding, &filename_or_null, &flags))
cx_freeze-7.2.8.tar.gz: cx_freeze-7.2.8/source/bases/common.c: Py_NoSiteFlag = 1;
cx_freeze-7.2.8.tar.gz: cx_freeze-7.2.8/source/bases/common.c: Py_FrozenFlag = 1;
cx_freeze-7.2.8.tar.gz: cx_freeze-7.2.8/source/bases/common.c: Py_IgnoreEnvironmentFlag = 1;
cython-3.0.11.tar.gz: cython-3.0.11/Cython/Utility/Exceptions.c: #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
cython-3.0.11.tar.gz: cython-3.0.11/Cython/Utility/Exceptions.c: // Py_OptimizeFlag is deprecated in Py3.12+ and not available in the Limited API.
cython-3.0.11.tar.gz: cython-3.0.11/Cython/Utility/Exceptions.c: #define __pyx_assertions_enabled()  (!Py_OptimizeFlag)
hunspell-0.5.5.tar.gz: hunspell-0.5.5/hunspell.cpp: /* TODO: Please review if there is any shorter/nicer;less clumsy way to convert args to  PyStrings using Py_FileSystemDefaultEncoding in python 2.x */
hunspell-0.5.5.tar.gz: hunspell-0.5.5/hunspell.cpp: if (!PyArg_ParseTuple(args, "etet", Py_FileSystemDefaultEncoding, &dpath_ptr, Py_FileSystemDefaultEncoding, &apath_ptr))
hunspell-0.5.5.tar.gz: hunspell-0.5.5/hunspell.cpp: if (!PyArg_ParseTuple(args, "et", Py_FileSystemDefaultEncoding, &dpath_ptr))
lmdb-1.6.2.tar.gz: lmdb-1.6.2/lmdb/cpython.c: return PyUnicode_AsEncodedString(src, Py_FileSystemDefaultEncoding,
mpi4py-4.0.1.tar.gz: mpi4py-4.0.1/src/mpi4py/MPI.src/atimport.pxi: #  define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-cpython.sym: -U _Py_FileSystemDefaultEncodeErrors
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-cpython.sym: -U _Py_FileSystemDefaultEncoding
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-cpython.sym: -U _Py_HasFileSystemDefaultEncoding
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-cpython.sym: -U _Py_UTF8Mode
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_BytesWarningFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_DebugFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_DontWriteBytecodeFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_FrozenFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_HashRandomizationFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_IgnoreEnvironmentFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_InspectFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_InteractiveFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_IsolatedFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_NoSiteFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_NoUserSiteDirectory
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_OptimizeFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_QuietFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_UnbufferedStdioFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _PyPy_VerboseFlag
nanobind-2.4.0.tar.gz: nanobind-2.4.0/cmake/darwin-ld-pypy.sym: -U _Py_FileSystemDefaultEncoding
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/InspectPatcher.c: if (Py_NoSiteFlag == 0) {
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_DebugFlag = 0;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_InspectFlag = 0;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_InteractiveFlag = 0;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_OptimizeFlag = SYSFLAG_OPTIMIZE;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_DontWriteBytecodeFlag = SYSFLAG_DONTWRITEBYTECODE;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_NoUserSiteDirectory = SYSFLAG_NO_SITE;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_IgnoreEnvironmentFlag = 0;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_VerboseFlag = SYSFLAG_VERBOSE;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_BytesWarningFlag = SYSFLAG_BYTES_WARNING;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_UnbufferedStdioFlag = SYSFLAG_UNBUFFERED;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_HashRandomizationFlag = 0;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_UTF8Mode = SYSFLAG_UTF8;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: if (Py_UTF8Mode) {
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: if (Py_FileSystemDefaultEncoding == NULL) {
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_FileSystemDefaultEncoding = "utf-8";
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_HasFileSystemDefaultEncoding = 1;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_FrozenFlag = 1;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_NoSiteFlag = 1;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MainProgram.c: Py_NoSiteFlag = SYSFLAG_NO_SITE;
Nuitka-2.6.tar.gz: Nuitka-2.6/nuitka/build/static_src/MetaPathBasedLoader.c: static inline bool isVerbose(void) { return Py_VerboseFlag != 0; }
numpy-2.2.2.tar.gz: numpy-2.2.2/numpy/_core/src/multiarray/compiled_base.c: if (Py_OptimizeFlag > 1) {
numpy-2.2.2.tar.gz: numpy-2.2.2/numpy/_core/tests/test_numerictypes.py: reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1")
numpy-2.2.2.tar.gz: numpy-2.2.2/numpy/ma/tests/test_core.py: reason="no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1")
numpy-2.2.2.tar.gz: numpy-2.2.2/numpy/random/tests/test_direct.py: # no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1
numpy-2.2.2.tar.gz: numpy-2.2.2/numpy/random/tests/test_extending.py: # no docstrings present to inspect when PYTHONOPTIMIZE/Py_OptimizeFlag > 1
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_DebugFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_VerboseFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_QuietFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_InteractiveFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_InspectFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_OptimizeFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_NoSiteFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_BytesWarningFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_FrozenFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_IgnoreEnvironmentFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_DontWriteBytecodeFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_NoUserSiteDirectory: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_UnbufferedStdioFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")]
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_HashRandomizationFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_IsolatedFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_LegacyWindowsFSEncodingFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: pub static mut Py_LegacyWindowsStdioFlag: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/cpython/pydebug.rs: if Py_IgnoreEnvironmentFlag != 0 {
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/fileobject.rs: pub static mut Py_FileSystemDefaultEncoding: *const c_char;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/fileobject.rs: pub static mut Py_FileSystemDefaultEncodeErrors: *const c_char;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/fileobject.rs: pub static mut Py_HasFileSystemDefaultEncoding: c_int;
orjson-3.10.15.tar.gz: orjson-3.10.15/include/pyo3/pyo3-ffi/src/fileobject.rs: // skipped 3.12-deprecated Py_UTF8Mode
pygame-2.6.1.tar.gz: pygame-2.6.1/setup.py: # because Py_FileSystemDefaultEncoding is deprecated in 3.12.0a7
pygame-2.6.1.tar.gz: pygame-2.6.1/src_c/rwobject.c: PyObject *result = pg_EncodeString(obj, Py_FileSystemDefaultEncoding,
pygit2-1.17.0.tar.gz: pygit2-1.17.0/src/utils.h: #define Py_FileSystemDefaultEncodeErrors "surrogateescape"
pythonnet-3.0.5.tar.gz: pythonnet-3.0.5/src/runtime/PythonEngine.cs: /// https://docs.python.org/3/c-api/init.html#c.Py_NoSiteFlag
pythonnet-3.0.5.tar.gz: pythonnet-3.0.5/src/runtime/Runtime.Delegates.cs: Py_NoSiteFlag = (int*)GetFunctionByName(nameof(Py_NoSiteFlag), GetUnmanagedDll(_PythonDll));
pythonnet-3.0.5.tar.gz: pythonnet-3.0.5/src/runtime/Runtime.Delegates.cs: internal static int* Py_NoSiteFlag { get; }
pythonnet-3.0.5.tar.gz: pythonnet-3.0.5/src/runtime/Runtime.cs: *Delegates.Py_NoSiteFlag = 1;
pythonnet-3.0.5.tar.gz: pythonnet-3.0.5/src/runtime/Runtime.cs: return *Delegates.Py_NoSiteFlag;
pyuwsgi-2.0.28.post1.tar.gz: pyuwsgi-2.0.28.post1/plugins/python/python_plugin.c: {"no-site", no_argument, 0, "do not import site module", uwsgi_opt_true, &Py_NoSiteFlag, 0},
pyuwsgi-2.0.28.post1.tar.gz: pyuwsgi-2.0.28.post1/plugins/python/python_plugin.c: Py_OptimizeFlag = up.optimize;
rook-0.1.209.tar.gz: rook-0.1.209/rook/native_extensions/cpython_importhook.cc: if ((exception == NULL) || Py_VerboseFlag) {
scandir-1.10.0.tar.gz: scandir-1.10.0/_scandir.c: // Because on PyPy, Py_FileSystemDefaultEncoding is (was) defined to be NULL
scandir-1.10.0.tar.gz: scandir-1.10.0/_scandir.c: #define FS_ENCODING (Py_FileSystemDefaultEncoding ? Py_FileSystemDefaultEncoding : "UTF-8")
SimpleParse-2.2.4.tar.gz: SimpleParse-2.2.4/simpleparse/stt/TextTools/mxTextTools/mx.h: if (!Py_DebugFlag)
SimpleParse-2.2.4.tar.gz: SimpleParse-2.2.4/simpleparse/stt/TextTools/mxTextTools/mx.h: if (!Py_DebugFlag)
SimpleParse-2.2.4.tar.gz: SimpleParse-2.2.4/simpleparse/stt/TextTools/mxTextTools/mxstdlib.h: #  define DPRINTF if (Py_DebugFlag) mxDebugPrintf
SimpleParse-2.2.4.tar.gz: SimpleParse-2.2.4/simpleparse/stt/TextTools/mxTextTools/mxstdlib.h: #  define IF_DEBUGGING if (Py_DebugFlag)
SimpleParse-2.2.4.tar.gz: SimpleParse-2.2.4/simpleparse/stt/TextTools/mxTextTools/mxstdlib.h: #  define DEBUGGING (Py_DebugFlag > 0)
subprocess32-3.5.4.tar.gz: subprocess32-3.5.4/_posixsubprocess_helpers.c: if (Py_FileSystemDefaultEncoding)
subprocess32-3.5.4.tar.gz: subprocess32-3.5.4/_posixsubprocess_helpers.c: Py_FileSystemDefaultEncoding,
uwsgi-2.0.28.tar.gz: uwsgi-2.0.28/plugins/python/python_plugin.c: {"no-site", no_argument, 0, "do not import site module", uwsgi_opt_true, &Py_NoSiteFlag, 0},
uwsgi-2.0.28.tar.gz: uwsgi-2.0.28/plugins/python/python_plugin.c: Py_OptimizeFlag = up.optimize;

It would feel safer to merge such change once the number of affected projects would be 10 or less.

Porting code to PyConfig_Get() is not trivial, since this function was only added to Python 3.14 and it has a different API (more complex than reading a variable). The pythoncapi-compat project can be used to get this function on Python 3.13 and older.

Cython has such complex code just to replace the deprecated Py_OptimizeFlag function:

#if CYTHON_COMPILING_IN_LIMITED_API  ||  (CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030C0000)
  // Py_OptimizeFlag is deprecated in Py3.12+ and not available in the Limited API.
  static int __pyx_assertions_enabled_flag;
  #define __pyx_assertions_enabled() (__pyx_assertions_enabled_flag)

  static int __Pyx_init_assertions_enabled(void) {
    PyObject *builtins, *debug, *debug_str;
    int flag;
    builtins = PyEval_GetBuiltins();
    if (!builtins) goto bad;
    // Not using PYIDENT() here because we probably don't need the string more than this once.
    debug_str = PyUnicode_FromStringAndSize("__debug__", 9);
    if (!debug_str) goto bad;
    debug = PyObject_GetItem(builtins, debug_str);
    Py_DECREF(debug_str);
    if (!debug) goto bad;
    flag = PyObject_IsTrue(debug);
    Py_DECREF(debug);
    if (flag == -1) goto bad;
    __pyx_assertions_enabled_flag = flag;
    return 0;
  bad:
    __pyx_assertions_enabled_flag = 1;
    // We (rarely) may not have an exception set, but the calling code will call PyErr_Occurred() either way.
    return -1;
  }
#else
  #define __Pyx_init_assertions_enabled()  (0)
  #define __pyx_assertions_enabled()  (!Py_OptimizeFlag)
#endif

@picnixz
Copy link
Member Author

picnixz commented May 8, 2025

It would feel safer to merge such change once the number of affected projects would be 10 or less.

Let's do it that way. For now, I'll only keep the docs changes and revert the runtime changes (I'll anyway need to do that eventually).

@picnixz picnixz marked this pull request as draft May 8, 2025 12:56
@hugovk
Copy link
Member

hugovk commented May 8, 2025

I'll only keep the docs changes

How will people know these are deprecated, if it's not documented?

We have 12 months until 3.15's feature freeze (and and 17 until 3.15's release), things may have changed in that time. We can also open issues/PRs with the above projects.

  • pillow (11.1.0)

Which deprecated variables is Pillow using? I don't recall any deprecation warnings.

@picnixz
Copy link
Member Author

picnixz commented May 8, 2025

How will people know these are deprecated, if it's not documented?

The symbols are marked with __attribute__((deprecated)), so the compiler would have warned them (I guess?) Do you mean that we should keep the documentation entries? I thought we removed them in general

@hugovk
Copy link
Member

hugovk commented May 8, 2025

The symbols are marked with __attribute__((deprecated)), so the compiler would have warned them (I guess?)

Hmm, nothing at https://github.com/python-pillow/Pillow/actions/runs/14906674072/job/41870605210?pr=8948

Do you mean that we should keep the documentation entries?

Yes.

This PR isn't removing any deprecations, it's only removing documentation about them.

If we only remove the docs, we might end up keeping the deprecations in 3.15, making their status unclear.

Let's remove the deprecations and their docs at the same time.

@picnixz
Copy link
Member Author

picnixz commented May 8, 2025

If we only remove the docs, we might end up keeping the deprecations in 3.15, making their status unclear.

Ah, I see what you mean. Ok let's remove them in one go. Or if someone else has a cleaner PR for the runtime changes, they can just merge this one into theirs and they don't need to update the docs themselves.

@vstinner
Copy link
Member

vstinner commented May 8, 2025

Which deprecated variables is Pillow using? I don't recall any deprecation warnings.

Pillow uses Py_FileSystemDefaultEncoding: source.

    if (!PyArg_ParseTupleAndKeywords(
            args,
            kw,
            "etf|nsy#n",
            kwlist,
            Py_FileSystemDefaultEncoding,  # <==== HERE ====
            &filename,
            &size,
            &index,
            &encoding,
            &font_bytes,
            &font_bytes_size,
            &layout_engine
        )) {
        return NULL;
    }

Oh, but this code path is only taken on Python 3.10 and older! So you can ignore Pillow which is up to date!

@hugovk
Copy link
Member

hugovk commented May 8, 2025

Hooray! Although I don't see any deprecations in the 3.9 build logs, should there be?

@vstinner
Copy link
Member

vstinner commented May 8, 2025

Hooray! Although I don't see any deprecations in the 3.9 build logs, should there be?

No, the deprecation was added later.

@hugovk
Copy link
Member

hugovk commented May 9, 2025

OK, thanks.


Unrelated to this issue, I wanted to see what the deprecation looks like. Just for testing, I edited the Pillow code so it only has a code path hitting the deprecation. A normal pip install -e . on Python 3.14.0b1 doesn't show any warnings, but it does with --verbose:

  src/_imagingft.c:145:13: warning: 'Py_FileSystemDefaultEncoding' is deprecated [-Wdeprecated-declarations]
    145 |             Py_FileSystemDefaultEncoding,
        |             ^
  /Library/Frameworks/Python.framework/Versions/3.14/include/python3.14/fileobject.h:22:1: note: 'Py_FileSystemDefaultEncoding' has been explicitly marked deprecated here
     22 | Py_DEPRECATED(3.12) PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
        | ^
  /Library/Frameworks/Python.framework/Versions/3.14/include/python3.14/pyport.h:280:54: note: expanded from macro 'Py_DEPRECATED'
    280 | #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
        |                                                      ^

Neither uv pip install -e . nor with --verbose showed the deprecation.

It's unfortunate that neither show the warning in normal use, as their maintainers will be less likely to see them. Perhaps something to raise with pip and uv.

@picnixz
Copy link
Member Author

picnixz commented May 9, 2025

It's unfortunate that neither show the warning in normal use, as their maintainers will be less likely to see them. Perhaps something to raise with pip and uv.

I think it'd be a good idea yes. Should we raise it for both? or is uv bundling part of pip and it suffices to just change pip?

@picnixz
Copy link
Member Author

picnixz commented May 9, 2025

@vstinner @hugovk Actually, there were two variables that were slated for removal and notified in 3.12 What's New I think but they never had a deprecated-removed directive and only the deprecation version is rendered. Those are Py_UTF8Mode and Py_InteractiveFlag.

Should we push the removal version to 3.16 or just delay the removal of all variables?

@vstinner
Copy link
Member

vstinner commented May 9, 2025

Actually, there were two variables that were slated for removal and notified in 3.12 What's New I think but they never had a deprecated-removed directive and only the deprecation version is rendered. Those are Py_UTF8Mode and Py_InteractiveFlag.

Both variables emit deprecation warnings using Py_DEPRECATED():

Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_UTF8Mode;
Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_InteractiveFlag;

I don't think that the doc is a big deal here, Py_DEPRECATED() is more important.

@vstinner
Copy link
Member

vstinner commented May 9, 2025

Also, all global configuration variables are documented in "Pending removal in Python 3.15": https://docs.python.org/dev/whatsnew/3.14.html#id13

@picnixz
Copy link
Member Author

picnixz commented May 9, 2025

Ok, I'll update the docs first for 3.13 and 3.14. I always hate doing backports, so would it be fine for me to first update main and let the bot make the backports automatically? that way, even 3.15 is consistent.

One way why I can think of why it's annoying to users is that they don't necessarily land on the What's New page if they make a Google search.

@hugovk
Copy link
Member

hugovk commented May 9, 2025

I think it'd be a good idea yes. Should we raise it for both?

Yes, raised in the PyPA/pip Discord and they asked to comment here: pypa/pyproject-hooks#157 (comment)

or is uv bundling part of pip and it suffices to just change pip?

uv is all Rust, no Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants