Class Variable Access and Assignment

Steve Holden steve at holdenweb.com
Fri Nov 4 06:38:22 EST 2005


Paul Rubin wrote:
> Stefan Arentz <stefan.arentz at gmail.com> writes:
> 
>>>Are you seriously saying there's lots of Python projects that would
>>>break if this particular weirdness were fixed?
>>
>>I have no numbers of course. But, why is this a weirdness? 
> 
> 
> Do you seriously think the number is larger than zero?  Do you think
> that's any good way to write code?
> 
Well it would break the Medusa asyncore/asynchat-based server software, 
so I can confidently predict the number would be greater than zero, yes.

Several fine programmers have relied on the (documented) behavior, I 
suspect, as it's a convenient way to install per-instance defaults, for 
example.

> Examples of the weirdness have already been given.  My favorite is the
> one where b.a is a list instead of an integer, in which case the class
> variable gets updated instead of an instance variable getting created.
> If you don't find the inconsistency to be weird, then ducky for you.

Ho, hum.
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list