Class Variable Access and Assignment

Bengt Richter bokr at oz.net
Mon Nov 7 13:25:10 EST 2005


On Mon, 07 Nov 2005 12:05:40 +0100, Magnus Lycka <lycka at carmen.se> wrote:

>First of all, I've still not heard any sensible suggestions
>about a saner behaviour for augmented assignment or for the
>way Python searches the class scope after the instance scope.
A nit, but a sizeable one: For new-style classes, the class scope
is searched first for a descriptor that may trump the instance logic.
>
>What do you suggest?
>
>Today, x += n acts just as x = x + n if x is immutable.
>Do you suggest that this should change?
A descriptor allows you to make it do as you like, so it's
a matter of discussing default behavior, not what you
are locked into (although costs re optimization could be a topic).

>

>Today, instance.var will look for var in the class
>scope if it didn't find it in the instance scope. Do
>you propose to change this?
It is already changed, for new-style classes. It is only if
a data descriptor is NOT found in the class hierarchy that
an existing instance variable is accessed as "usual".

>
>Or, do you propose that we should have some second order
>effect that makes the combination of instance.var += n
>work in such a way that these features are no longer
>orthogonal?
I don't think he is proposing anything, just defending against
what he considers misinterpretations of what he is saying.
Given how hard it is to say ANYTHING and be understood EXACTLY,
this tends towards a pursuit of quantum nits ;-)
I suspect we all experience the emotions relevant to being misunderstood;
we just stop at different nit granularities (modulo horn locking ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list