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
Autogenerate signature for METH_NOARGS and perhaps METH_O extension functions #84805
It would be nice if METH_NOARGS extension methods had an autogenerated signature (or rather, autogenerated __text_signature__ that gets picked up by inspect.signature). After all, the signature is trivially known at compile time.
The same could possibly be done for METH_O methods, for which the effective signature is known too. The name of the sole parameter is not known, but given that the parameter is (I believe?) positional only, that name "shouldn't" really matter (in the sense, e.g., that whether signature.bind() succeeds or not doesn't depend on the parameter name).
It is an interesting idea and I implemented it in #107794.
The one difference with Argument Clinic generated signature is that it names the first implicit argument $module in module-level functions and $self in unbound methods, while my PR use $self in both cases. But it does not matter, because it is always removed in module-level functions. The end user never sees a difference until it looks at __text_signature__ directly.
Activity
anntzer commentedon May 14, 2020
It would be nice if METH_NOARGS extension methods had an autogenerated signature (or rather, autogenerated __text_signature__ that gets picked up by inspect.signature). After all, the signature is trivially known at compile time.
The same could possibly be done for METH_O methods, for which the effective signature is known too. The name of the sole parameter is not known, but given that the parameter is (I believe?) positional only, that name "shouldn't" really matter (in the sense, e.g., that whether
signature.bind()succeeds or not doesn't depend on the parameter name).pythongh-84805: Autogenerate signature for METH_NOARGS and METH_O extâĶ
serhiy-storchaka commentedon Aug 9, 2023
It is an interesting idea and I implemented it in #107794.
The one difference with Argument Clinic generated signature is that it names the first implicit argument
$modulein module-level functions and$selfin unbound methods, while my PR use$selfin both cases. But it does not matter, because it is always removed in module-level functions. The end user never sees a difference until it looks at__text_signature__directly.gh-84805: Autogenerate signature for METH_NOARGS and METH_O extensionâĶ