On Tue, Aug 30, 2016 at 02:20:26PM -0700, Guido van Rossum wrote:

> - Whether (given PEP 484's relative success) it's worth adding syntax
> for variable/attribute annotations.

The PEP makes a good case that it does.


> - Whether the keyword-free syntax idea proposed here is best:
>   NAME: TYPE
>   TARGET: TYPE = VALUE

I think so.

That looks like similar to the syntax used by TypeScript:

http://www.typescriptlang.org/docs/handbook/type-inference.html

let zoo: Animal[] = [new Rhino(), new Elephant(), new Snake()];


Some additional thoughts:

Is it okay to declare something as both an instance and class attribute?

class X:
    spam: int
    spam: ClassVar[Str] = 'suprise!'

    def __init__(self):
        self.spam = 999


I would expect it should be okay.



It is more common in Python circles to talk about class and instance 
*attributes* than "variables". Class variable might be okay in a 
language like Java where classes themselves aren't first-class values, 
but in Python "class variable" always makes me think it is talking about 
a variable which is a class, just like a string variable or list 
variable. Can we have ClassAttr[] instead of ClassVar[]?


Other than that, +1 on the PEP.



-- 
Steve
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to