[Python-ideas] Proposal: Use mypy syntax for function annotations

Stefan Behnel stefan_ml at behnel.de
Thu Aug 14 19:53:44 CEST 2014


Neal Becker schrieb am 14.08.2014 um 19:33:
> Does mypy support annotation of functions implemented in C code?
> 
> If I extend cpython via C-API, does mypy provide a mechanism to annotate those 
> functions?

No, mypy isn't about C or even CPython.

However, you can already do that, although not easily, I think. What you'd
need is an __annotations__ dict on the function object and a bit of
trickery to make CPython believe it's a function. Cython gives you that for
free (by simply providing the normal Python semantics), but you can get the
same thing with some additional work when writing your own C code. There's
also the argument clinic, but IIRC it doesn't support signature annotations
for some reason, guess it wasn't considered relevant (yet).

Stefan




More information about the Python-ideas mailing list