Is structures of builtin types are guarded by deprecation process?

I added Py_DEPRECATED(3.11) to PyBytesObject.ob_shash because I wanted to remove it in 3.13.
But deprecating it is more difficult than removing it for numpy developer. They asked to provide a clean way to avoid deprecation warning.
(Deprecate ob_shash in BytesObject · Issue #91020 · python/cpython · GitHub)

Before adding another API for numpy and other libraries subclassing bytes object but don’t want to call bytes.__new__(), I want to make it clear that we really need to add Py_DEPRECATED to structure members.

We change the implementation of builtin types some time.
For example, there is discussion about changing long object (More efficient implementation of integers · Discussion #147 · faster-cpython/ideas · GitHub).

Do we need to add Py_DEPRECATED and wait two releases before changing the structure of builtin objects?

It would be great to remove PyUnicodeObject structure members from the public C API to be able to change the implementation details tomorrow (ex: experiment UTF-8) or ease interoperability with other Python implementations (PyPy uses UTF-8, not PEP 393).

2 Likes

My PEP 620 covers the general topic of making structures opaque in Python long term: PEP 620 – Hide implementation details from the C API | peps.python.org The new HPy API basically make all structures opaque.

2 Likes