mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[mypyc] Generate introspection signatures for compiled functions

Open brianschubert opened this issue 6 months ago • 0 comments

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).

brianschubert avatar Jun 16 '25 21:06 brianschubert