[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484
Ethan Furman
ethan at stoneleaf.us
Thu Aug 4 15:44:53 EDT 2016
On 08/04/2016 12:11 PM, Daniel Moisset wrote:
> I follow the example perfectly. Now suppose a reader finds the following
> piece of code:
>
> class Starship:
> stats: class Dict[str, int] = {} # Pure class variable
> damage: class int = 0 # Hybrid class/instance variable
> captain: str # Pure instance variable
> speed: float = 0
>
> I added a new attribute (similar to b in your original example). Given
> that the type declaration doesn't say "class",the reader might be
> inclined to think it's an instance variable. But in runtime (if I got
> you right), that variable will be stored in "Starship.__dict__" and
> writing "Starship.speed = 3" will change the speed of those starship
> instances that still haven't set the attribute.
The type checker should flag that as a bug, since Starship.speed is
supposed to be an instance variable.
--
~Ethan~
More information about the Python-ideas
mailing list