[Python-ideas] Proposal to extend PEP 484 (gradual typing) to support Python 2.7

Steven D'Aprano steve at pearwood.info
Fri Jan 8 21:08:10 EST 2016


On Fri, Jan 08, 2016 at 03:04:58PM -0800, Guido van Rossum wrote:

[...]
> Since Python 2 doesn't support function annotations we've had to look for
> alternatives. We considered stub files, a magic codec, docstrings, and
> additional `# type:` comments. In the end we decided that `# type:`
> comments are the most robust approach. We've experimented a fair amount
> with this and we have a proposal for a standard.

[...]
> - Stub files: this would complicate the analysis in mypy quite a bit,
> because it would have to parse both the .py file and the .pyi file and
> somehow combine the information gathered from both, and for each function
> it would have to use the types from the stub file to type-check the body of
> the function in the .py file. This would require a lot of additional
> plumbing. And if we were using Python 3 we would want to use in-line
> annotations anyway.

I don't understand this paragraph. Doesn't mypy (and any other type 
checker) have to support stub files? I thought that stub files are 
needed for extension files, among other things. So I would have expected 
that any Python 2 type checker would have to support stub files as well, 
regardless of whether inline #type comments are introduced or not.

Will Python 3 type checkers be expected to support #type comments as 
well as annotations and stub files?



-- 
Steve


More information about the Python-ideas mailing list