[Python-ideas] PEP 484 (Type Hints) -- first draft round

Andrew Barnert abarnert at yahoo.com
Sat Jan 24 06:11:56 CET 2015

On Friday, January 23, 2015 8:41 PM, Guido van Rossum <guido at python.org> wrote:

>FWIW, I just remembered that there is actually a really cool stub generator that's part of mypy: pinfer (written or at least greatly improved by Dropbox intern Jared Pochtar last summer). It runs your program (typically a unittest suite) and through introspection discovers the argument types of all methods that are called. There's also an old mypy issue referring to an old mypy wiki page about stub generation.

That's very cool. And it seems like something that different implementations could usefully compete on.

For an extreme example, PyPy has within it an algorithm to statically walk all code paths in your bytecode and infer all types for RPython. Modifying that to handle full Python by falling back to Any instead of raising an exception when it finds a potentially heterogeneous collection or a use of eval or whatever seems like it might be a plausible project. Although it would probably be a whole lot slower than the mypy stub generator, it might also be useful as something you only run once/release.

More information about the Python-ideas mailing list