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

Manuel Cerón ceronman at gmail.com
Thu Aug 14 00:27:54 CEST 2014


On Wed, Aug 13, 2014 at 9:44 PM, Guido van Rossum <guido at python.org> wrote:

> [There is no TL;DR other than the subject line. Please read the whole
> thing before replying. I do have an appendix with some motivations for
> adding type annotations at the end.]
>

This is a very interesting idea. I played a bit with function annotations (
https://github.com/ceronman/typeannotations) and I gave a talk about them
at EuroPython 2013. Certainly static type analysis is probably the best use
case.

The curious thing here is that while standardizing a syntax for type
> annotations, we technically still won't be adopting standard rules for type
> checking. This is intentional. First of all, fully specifying all the type
> checking rules would make for a really long and boring PEP (a much better
> specification would probably be the mypy source code). Second, I think it's
> fine if the type checking algorithm evolves over time, or if variations
> emerge. The worst that can happen is that you consider your code correct
> but mypy disagrees; your code will still run.
>
> That said, I don't want to *completely* leave out any specification. I
> want the contents of the typing.py module to be specified in the PEP, so
> that it can be used with confidence. But whether mypy will complain about
> your particular form of duck typing doesn't have to be specified by the
> PEP. Perhaps as mypy evolves it will take options to tell it how to handle
> certain edge cases. Forks of mypy (or entirely different implementations of
> type checking based on the same annotation syntax) are also a possibility.
> Maybe in the distant future a version of Python will take a different
> stance, once we have more experience with how this works out in practice,
> but for Python 3.5 I want to restrict the scope of the upheaval.
>

The type checking algorithm might evolve over the time, but by including
typing.py in the stdlib, the syntax for annotations would be almost frozen
and that will be a limitation. In other projects such as TypeScript (
http://www.typescriptlang.org/), that the syntax usually evolves alongside
the algorithms.

Is the syntax specifyed in typing.py mature enough to put it in the stdlib
and expect users to start annotating their projects without worrying too
much about future changes?

Is there enough feedback from users using mypy in their projects?

I think that rushing typing.py into 3.5 is not a good idea. However, It'd
be nice to add some notes in PEP8, encourage it's use as an external
library, let some projects and tools (e.g. PyCharm) use it. It's not that
bad if mypy lives 100% outside the Python distribution for a while. Just
like TypeScript to JavaScript. After getting some user base, part of it
(typing.py) could be moved to the stdlib.

Manuel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140814/eb99215a/attachment.html>


More information about the Python-ideas mailing list