Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Feature or enhancement
ThePyType_FromSpec family of functions provides a convenient and forward-compatible way mechanism for creating new types. It could in principle also be used to createcallables providing aPEP-590 vector call interface, which has significant performance benefits for binding libraries (see therelated discussion here).
One can already specify a member named__vectorcalloffset__ inPyType_FromSpec. This isn't fully working in the limited API, however. I encountered the following problems.
- The
Py_TPFLAGS_HAVE_VECTORCALLflag is not part of the limited API. - The
PyVectorcall_NARGS()helper function is not part of the limited API. - One would normally set
tp_callto the compatibility dispatch routinePyVectorcall_Call. It is, however, also not part of the public ABI. - Leaving
tp_callunspecified is not an option.PyType_Ready()even throws an exception intype_ready_pre_checks()whentp_callis unspecified.
Pitch
I propose the following changes:
- Adding
Py_TPFLAGS_HAVE_VECTORCALL,PyVectorcall_NARGS(), andPyVectorcall_Call()to the limited API. - Redundant, but nice: Setting
tp_calltoPyVectorcall_CallwhenPyType_Readyencounters a type that doesn't have this field set.
Note that vector calls can bereceived andperformed. This issue is just about the receiving end.
Previous discussion
See the discord threadhttps://discuss.python.org/t/ideas-for-forward-compatible-and-fast-extension-libraries-in-python-3-12/15993/12.