Type Signatures for extension modules (PEP draft)

Ok, here is a draft in my fork of peps repo: PEP 743: Signatures for extension modules by skirpichev · Pull Request #2 · skirpichev/peps · GitHub

This proposal instead suggests using the __signature__ attribute, the __text_signature__ will be deprecated (or we could just remove it?). That is merely a cosmetic change, however. More important difference is using a different endmarker (\n\n vs --\n\n) to separate a “signature line” and the rest of docstring. In short, this proposal formalizes a “signature line” notion in the PEP 7.

@encukou, let me know if you would like to sponsor this PEP or be a coauthor. If you agree, should I first finish implementation fully before posting a pr against the peps repo?

In the proposed version, the __signature__ will be implemented as a managed attribute, that parses text signature from the docstring and uses inspect._signature_fromstr() to construct the Signature object.

That opportunity was mentioned in the PEP as an alternative. The downside I see here is that it mixes support for optional typing hints (generally, we don’t have type annonations in the stdlib) and more basic support for introspection signatures in extension modules, that already used in the CPython stdlib e.g. in the help() builtin.

This sounds for me more as a AC alternative/public variant of.

I would appreciate you opinion on the proposed PEP.

2 Likes