[Python-Dev] Please reject or postpone PEP 526

Mark Shannon mark at hotpy.org
Sun Sep 4 07:31:26 EDT 2016



On 02/09/16 20:33, Guido van Rossum wrote:
> On Fri, Sep 2, 2016 at 10:47 AM, Steve Dower <steve.dower at python.org> wrote:
>> "I'm not seeing what distinction you think you are making here. What
>> distinction do you see between:
>>
>>     x: int = func(value)
>>
>> and
>>
>>     x = func(value)  # type: int"
>>
>> Not sure whether I agree with Mark on this particular point, but the
>> difference I see here is that the first describes what types x may ever
>> contain, while the latter describes what type of being assigned to x right
>> here. So one is a variable annotation while the other is an expression
>> annotation.
>
> But that's not what type comments mean! They don't annotate the
> expression. They annotate the variable. The text in PEP 484 that
> introduces them is clear about this (it never mentions expressions,
> only variables).

In PEP 484, the section on type comments says:
(Quoting verbatim)
"""
No first-class syntax support for explicitly marking variables as being 
of a specific type is added by this PEP. To help with type inference in 
complex cases, a comment of the following format may be used...
"""

Some mentions of the type of a variable are made in other places in the 
PEP, but those were all added *after* I had approved the PEP.

In other words PEP 484 specifically states that annotations are to help 
with type inference. As defined in PEP 526, I think that type 
annotations become a hindrance to type inference.

Cheers,
Mark.

>
>> Personally, I prefer expression annotations over variable annotations, as
>> there are many other languages I'd prefer if variable have fixed types (e.g.
>> C++, where I actually enjoy doing horrible things with implicit casting ;)
>> ).
>>
>> Variable annotations appear to be inherently restrictive, so either we need
>> serious clarification as to why they are not, or they actually are and we
>> ought to be more sure that it's the direction we want the language to go.
>
> At runtime the variable annotations are ignored. And a type checker
> will only ask for them when it cannot infer the type. So I think we'll
> be fine.
>


More information about the Python-Dev mailing list