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

Ed Kellett edk141 at gmail.com
Mon Aug 25 18:07:37 CEST 2014


On 25 Aug 2014 16:29, "Guido van Rossum" <guido at python.org> wrote:
> > … or we could have a decorator for type hints, and ascribe no new
> > meaning at all to __annotations__. Or assume __annotations__ contains
> > type hints iff all the annotations present are instances of typing.*.
> > That might be better anyway, since a decorator could then add (or
> > augment) type information without assigning to __annotations__ (which
> > would be weird).
> >
> > Even if conveying type information is the most useful use of
> > annotations, there's no reason it can't be explicit (and consistent
> > with other uses of annotations).
>
> All that sounds fine, but you still have to have a way to convey all that
information to the type checker. Remember, the type checker cannot (or
doesn't want to) execute the code and it can only see annotations in their
original syntactic form. (But it can indeed be told about certain
decorators.)

That's reasonable - I was imagining the decorator for type hints wouldn't
do anything (apart from possibly marking the function as having type
hints), it would just be there to tell the static checker "this function
should be type-checked ".

Ed Kellett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140825/a8a3ef37/attachment-0001.html>


More information about the Python-ideas mailing list