mypy
mypy copied to clipboard
[mypyc] Generate introspection signatures for compiled functions
Refs https://github.com/mypyc/mypyc/issues/838
This PR populates __text_signature__ for compiled functions, making runtime signature introspection possible (i.e. inspect.signature(func)).
While __text_signature__ is an undocumented CPython implementation detail, other extension module generators are using it in practice. For example, PyO3 and Cython both support it. I think it would be reasonable for mypyc to support it too.
Some function signatures can't be represented by __text_signature__ (namely, those with complex default arguments). In those cases, no signatures are generated (same as the current behavior).