New GitHub issue #93274 from wjakob:<br>
<hr>
<pre>
**Feature or enhancement**
The `PyType_FromSpec` family of functions provides a convenient and forward-compatible way mechanism for creating new types. It could in principle also be used to create _callables_ providing a PEP-590 vector call interface, which has significant performance benefits for binding libraries (see the related discussion here https://discuss.python.org/t/ideas-for-forward-compatible-and-fast-extension-libraries-in-python-3-12/15993/12).
One can already a member named `__vectorcalloffset__` in `PyType_FromSpec`. This isn't fully working in the limited API, however.
1. The `Py_TPFLAGS_HAVE_VECTORCALL` flag is not part of the limited API.
2. `PyVectorcall_NARGS` is not part of the limited API.
3. One would normally set `tp_call` to the compatibility dispatch routine `PyVectorcall_Call`. It is, however, also not part of the public ABI.
4. Leaving `tp_call` unspecified is not an option. `PyType_Ready()` even throws an exception in `type_ready_pre_checks()` when `tp_call` is unspecified.
**Pitch**
I propose the following changes:
1. Adding Py_TPFLAGS_HAVE_VECTORCALL to the public API.
2. Adding `PyVectorcall_NARGS()` to the limited API.
3. Adding `PyVectorcall_Call()` to the `Py_LIMITED_API`.
4. Redundant, but nice: Setting `tp_call` to `PyVectorcall_Call` when `PyType_Ready` encounters a type that doesn't have this field set.
**Previous discussion**
See the discord thread https://discuss.python.org/t/ideas-for-forward-compatible-and-fast-extension-libraries-in-python-3-12/15993/12.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/93274">View on GitHub</a>
<p>Labels: type-feature</p>
<p>Assignee: </p>