Description
Feature or enhancement
Proposal:
In the referenced d.p.o thread it was proposed using stub files to get inspect.Signature's for extension modules.
Currently, there is no public interface to provide such data for introspection. There is only private, undocumented __text_signature__
attribute, which parsed by inspect.signature()
. This interface also incomplete, e.g. it lacks support for return type annotations.
Lets use stub files as a fallback for extension modules: if callable has no __text_signature__
attribute - the inspect module should take look to stub files for the given module, import relevant stub object (with same import resolution ordering as for type checkers) and take it's signature. Later, the AC can be changed to generate stub files (or take them as input).
PS: Maybe same approach could work to support functions with multiple signatures, if the typing.get_overloads()
will fallback to stub files as well.
If this does make sense, I'll provide a draft implementation.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/type-signatures-for-extension-modules-pep-draft/43914/22