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

Andrew Barnert abarnert at yahoo.com
Fri Aug 15 08:28:11 CEST 2014


On Thursday, August 14, 2014 9:15 PM, Guido van Rossum <guido at python.org> wrote:

>On Thu, Aug 14, 2014 at 8:51 PM, Andrew Barnert <abarnert at yahoo.com.dmarc.invalid> wrote:
>
>>Most of the code in typing.py is a duplication of the ABCs in the collections.abc module (and io and maybe others). I understand that MyPy couldn't monkeypatch that code into the stdlib, so it had to fork the contents, but if this is going into the stdlib, can't we just modify collections/abc.py instead? Why not have the type information on collections.abc.Sequence be introspectable at runtime? More importantly, why not have the interface defined by collections.abc.Sequence be _exactly_ the same as the one checked by the static type checker, instead of just very similar?


[snip]

>I think I already responded to a similar proposal. I think modifying the existing ABCs is fine for Python 3.5 and beyond, but I think I'd like to keep aliasing in the typing module to make it easier to use annotations in earlier Python versions (using a typing.py installed from PyPI).

That sounds like a great idea. My worry wasn't the extra few KB of code sitting on my computer, it was the extra set of not-quite-the-same parallel concepts that are in typing.py today. If it instead has exactly the same classes as collections.abc, io, etc., everything's great.

>I feel similar about using a|b as a concise way to spell Union[a, n], and int|None would be quite decent as a way to spell optional int.


Swift makes you sound like a 12-year-old girl? who makes every phrase? sound like a question? by writing `int?` everywhere? Haskell maybe makes you sound wishy-washy and maybe a little uncertain by having you say `Maybe int`.  Python lets you declare, `int, or None` like Patrick Henry. Sounds good.


More information about the Python-ideas mailing list