You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C API] How many slots of static types should be exposed in PyType_GetSlot() #85784
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2020-08-23.08:48:18.095>labels= ['expert-C-API', 'type-feature', '3.10']
title='[C API] How many slots of static types should be exposed in PyType_GetSlot()'updated_at=<Date2021-01-16.05:36:16.127>user='https://github.com/shihai1991'
In order to resolve bpo-41073, we want to extend PyType_GetSlot() to accept static types. But there have another question we should be considered: How many slots should be exposed in PyType_GetSlot().
petr's opinion from PR-21931:I would not want to expose the Py_tp_as_* slots at all; their contents are covered in other slots that should be used instead. And slots like Py_tp_version_tag are specific to CPython; I don't think they should be exposed in the general C API.
IMO, a slot should be exposed if there is some reason for exposing it.
bpo-41073 talks about tp_dealloc, which is already exposed as Py_tp_dealloc.
Recently, Py_bf_* slots were exposed (but not as part of the limited API), in bpo-40724 which links to the reasons for exposing them.
Also: PyType_GetSlot should return a function pointer, not data.
For some slots (Py_tp_doc, Py_tp_methods, Py_tp_members, Py_tp_getset) that ship has sailed, but for new ones, we should honor the distinction between data and function pointers. The C standard says they're distinct, so it might bite us in the future (e.g. compiling to WebAssembly).
Not a function, shouldn't be used with PyType_Slot:
tp_dict - I'd add a PyType_GetDict if there is a need to get this
tp_mro - I'd add a PyType_GetMRO if there is a need to get this
(There are existing slots that aren't functions; I'd like to deprecate them in the long term.)
internal use only, do not expose:
tp_cache
tp_subclasses
tp_weaklist
tp_as_*
Not part of limited API, do not expose:
tp_vectorcall
Can be exposed if we deem all of the related API stable:
Not a function, shouldn't be used with PyType_Slot:
tp_dict - I'd add a PyType_GetDict if there is a need to get this
tp_mro - I'd add a PyType_GetMRO if there is a need to get this
I checked some other projects which use type fileds directly.
cpython doesn't expose the tp_dict and tp_mro directly in headers.
I am not sure which way is more better(calling function vs using fileld directly).
Activity
shihai1991 commentedon Aug 23, 2020
In order to resolve bpo-41073, we want to extend
PyType_GetSlot()to accept static types. But there have another question we should be considered: How many slots should be exposed inPyType_GetSlot().petr's opinion from PR-21931:I would not want to expose the Py_tp_as_* slots at all; their contents are covered in other slots that should be used instead. And slots like Py_tp_version_tag are specific to CPython; I don't think they should be exposed in the general C API.
shihai1991 commentedon Aug 23, 2020
related bpo: bpo-41073
encukou commentedon Sep 8, 2020
IMO, a slot should be exposed if there is some reason for exposing it.
bpo-41073 talks about tp_dealloc, which is already exposed as Py_tp_dealloc.
Recently, Py_bf_* slots were exposed (but not as part of the limited API), in bpo-40724 which links to the reasons for exposing them.
Which other slots are we missing?
encukou commentedon Oct 20, 2020
Also: PyType_GetSlot should return a function pointer, not data.
For some slots (Py_tp_doc, Py_tp_methods, Py_tp_members, Py_tp_getset) that ship has sailed, but for new ones, we should honor the distinction between data and function pointers. The C standard says they're distinct, so it might bite us in the future (e.g. compiling to WebAssembly).
shihai1991 commentedon Oct 30, 2020
Can we write those info to docs? In case some developer want to exposing slot in future.
nb_inserved in PyNumberMethods should be removed?
encukou commentedon Nov 3, 2020
Do you mean something like "only expose a slot if you have a reason for exposing it"? That sounds like a tautology.
Where in the docs would this go?
You mean nb_reserved, right?
It can't be removed; old-style initialization is positional.
But it could be replaced according to PEP-387:
encukou commentedon Nov 5, 2020
My views on individual slots:
Not a function, shouldn't be used with PyType_Slot:
(There are existing slots that aren't functions; I'd like to deprecate them in the long term.)
internal use only, do not expose:
Not part of limited API, do not expose:
Can be exposed if we deem all of the related API stable:
shihai1991 commentedon Nov 7, 2020
Add a friend Note in docs of
PyType_GetSlotMAYBE?encukou commentedon Dec 29, 2020
Documentation for developers *of* CPython should generally go in the dev guide, a comment in the code, or in issues like this.
shihai1991 commentedon Jan 16, 2021
I checked some other projects which use type fileds directly.
cpython doesn't expose the tp_dict and tp_mro directly in headers.
I am not sure which way is more better(calling function vs using fileld directly).
refs:
https://gitlab.gnome.org/GNOME/pygobject/-/blob/master/gi/gimodule.c#L1168
https://github.com/biolab/orange2/blob/db40a9449cb45b507d63dcd5739b223f9cffb8e6/source/orange/cls_orange.cpp#L587
vstinner commentedon Jan 28, 2025
At the end, nothing has to be done, and I just close the issue.
In the meanwhile (in 2020), PyType_GetSlot() was modified to accept static types: a13b26c.