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

Guido van Rossum guido at python.org
Thu Aug 14 01:30:10 CEST 2014


On Wed, Aug 13, 2014 at 3:28 PM, Todd <toddrjen at gmail.com> wrote:

> However, I still don't get this bit. Why would allowing type annotations
> automatically imply that no other annotations would be possible?  Couldn't
> we formalize what would be considered a type annotation while still
> allowing annotations that don't fit this criteria to be used for other
> things?
>

We certainly *could* do that. However, I haven't seen sufficient other uses
of annotations. If there is only one use for annotations (going forward),
annotations would be unambiguous. If we allow different types of
annotations, there would have to be a way to tell whether a particular
annotation is intended as a type annotation or not. Currently mypy ignores
all modules that don't import typing.py (using any form of import
statement), and we could continue this convention. But it would mean that
something like this would still require the typing import in order to be
checked by mypy:

import typing

def gcd(int a, int b) -> int:
    <tralala>

The (necessary) import would be flagged as unused by every linter in the
world... :-(

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140813/93bb632d/attachment.html>


More information about the Python-ideas mailing list