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

Ed Kellett edk141 at gmail.com
Mon Aug 25 12:20:03 CEST 2014


On 25 August 2014 07:18, Terry Reedy <tjreedy at udel.edu> wrote:
> On 8/24/2014 11:12 PM, Guido van Rossum wrote:
>
>> Finally, I would actually be okay if we found a way to let type hints
>> and other annotations coexist -- I just prefer type hints to be the
>> default use, since I see them as much more generally useful than all
>> other uses combined.
>
>
> I believe co-existence is possible, but the details will depend on the form
> type hints take. First, other annotations should be easily distinguished
> from type hints. Second, other annotations that would interfere with the
> runtime use of __annotations__ should be pulled out by a decorator and
> possibly moved to another attribute specific to the decorator (such as
> '_deco_name').

… 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).

Ed Kellett


More information about the Python-ideas mailing list