"no variable or argument declarations are necessary."
Paul Rubin
http
Wed Oct 5 04:03:53 EDT 2005
Duncan Booth <duncan.booth at invalid.invalid> writes:
> If you think variable declarations should be required,
I don't think they should be required. I think there should optional
declarations along with a compiler flag that checks for them if the
user asks for it, like Perl has.
> then you presumably want that to cover class attributes as well as
> local and global variables. After all assigning to 'x.i' when you
> meant 'x.j' is at least as bad as assigning to 'i'
Yes, lots of people mistakenly use __slots__ for exactly that purpose.
Maybe the function they think __slots__ is supposed to implement is a
legitimate one, and having a correct way to do it is a good idea.
> But unless you know the type of 'x', how do you know whether it
> has attributes 'i' or 'j'?
If the compiler knows (through declarations, type inference, or
whatever) that x is a certain type of class instance, then it knows
what attributes x has.
More information about the Python-list
mailing list