gh-105227: Add PyType_GetDict()#105747
Conversation
Doc/c-api/typeobj.rst
Outdated
| **<<>>**: Names in double angle brackets should be initially set to | ||
| ``NULL`` and treated as read-only after initialization. |
There was a problem hiding this comment.
Only marking up tp_dict implies it's the only one in this category. At least tp_bases & tp_mro should be marked too.
|
@Yhg1s needs to approve backporting to 3.12 |
Doc/c-api/type.rst
Outdated
| replacement for accessing :c:member:`~PyTypeObject.tp_dict` directly. | ||
| The returned dictionary must be treated as read-only. | ||
|
|
||
| This function isn't intended for general use. It's meant for |
There was a problem hiding this comment.
If it's not meant for general use, would it be better to add it as unstable API?
There was a problem hiding this comment.
To be honest, I think it makes more sense to say this is for general use.
erlend-aasland
left a comment
There was a problem hiding this comment.
Can you update Doc/data/refcounts.dat, so we get a "Return value: New reference" markup in the docs?
Doc/c-api/type.rst
Outdated
| This function isn't intended for general use. It's meant for | ||
| specific embedding and language-binding cases, where direct access | ||
| to the dict is necessary and indirect access (e.g. via the proxy) | ||
| isn't adequate. Extension modules may continue to use ``tp_dict``, | ||
| directly or indirectly, when setting up their own types. |
There was a problem hiding this comment.
Maybe elevate this paragraph to a .. note:, or maybe a .. warning:?
| The new :c:func:`PyType_GetDict` provides the dictionary for the given type | ||
| object that is normally exposed by ``cls.__dict__``. Normally it's | ||
| sufficient to use :c:member:`~PyTypeObject.tp_dict`, but for the static | ||
| builtin types ``tp_dict`` is now always ``NULL``. ``PyType_GetDict()`` |
There was a problem hiding this comment.
Formatting nit:
| builtin types ``tp_dict`` is now always ``NULL``. ``PyType_GetDict()`` | |
| builtin types :c:member:`!tp_dict` is now always ``NULL``. :c:func:`!PyType_GetDict()` |
Doc/c-api/type.rst
Outdated
| replacement for accessing :c:member:`~PyTypeObject.tp_dict` directly. | ||
| The returned dictionary must be treated as read-only. | ||
|
|
||
| This function isn't intended for general use. It's meant for |
There was a problem hiding this comment.
To be honest, I think it makes more sense to say this is for general use.
|
Sorry, I last track of which branch I had built CPython from 🐑 . What I meant to say is: I can confirm that the latest version of pyqt6 works with this branch so this change is critical. |
|
PyQt now uses this call. Strictly speaking it could do the C equivalent of 'cls.dict' but the call is much nicer. |
This should make pyqt6 build with Python 3.12. For more infor see: python#105747
This patch should make pyqt6 build with Python 3.12. For more info see: python#105747
|
I'm not available enough to merge this for a few weeks, so anyone that feels comfortable doing so is welcome to in the meantime. 😄 |
|
Any updates on this? This currently blocks me (with qutebrowser, via PyQt) from testing Python 3.12 on CI. |
|
Oh dear, I didn't realis a few weeks is all the time until Beta. And I was busy so it didn't reach the top of my TODO list. |
|
Thanks @ericsnowcurrently for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
This compensates for static builtin types having `tp_dict` set to `NULL`. (cherry picked from commit a840806) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
GH-106600 is a backport of this pull request to the 3.12 branch. |
|
Oh whoops, I wasn't even realizing how close to the Beta 4 I was commenting (apparently it was scheduled for yesterday, but not released yet?)! Glad to hear this still made it in, thanks so much @ericsnowcurrently and @encukou! |
|
FWIW, this PR was one of the reasons 3.12b4 wasn't cut yesterday :) |
|
|
||
| .. versionchanged:: 3.12 | ||
|
|
||
| Internals detail: For static builtin types, this is always ``NULL``. |
There was a problem hiding this comment.
Sorry for the post merge review, but FYI, there's a directive for implementation details: .. impl-detail::
|
Thanks for wrapping this up, @encukou! |
This compensates for static builtin types having
tp_dictset toNULL.tp_dictslot of static builtin types isNULLin 3.12, without mention in the changelog or an alternative #105227📚 Documentation preview 📚: https://cpython-previews--105747.org.readthedocs.build/