Python dot-equals (syntax proposal)

Chris Rebert clp2 at rebertia.com
Sun May 2 01:19:23 EDT 2010


On Sat, May 1, 2010 at 10:05 PM, Alf P. Steinbach <alfps at start.no> wrote:
> On 02.05.2010 06:06, * Aahz:
>> In article<4bdcd631$0$27782$c3e8da3 at news.astraweb.com>,
>> Steven D'Aprano<steve at REMOVE-THIS-cybersource.com.au>  wrote:
>>>
>>> On Sat, 01 May 2010 07:13:42 -0500, Tim Chase wrote:
>>>>
>>>> The += family of operators really do rebind the symbol, not modify the
>>>> object.
>>>
>>> They potentially do both, depending on the object, even for built-ins.
>>
>> No, they always rebind; sometimes they modify the object
>
> If they always rebind and sometimes modify object then they "potentially do
> both", and so the "No" at the start of the sentence contradicts this later
> part.
>
>
>> and sometimes
>> they rebind the original target to the same object.
>
> At the Python level that seems to be an undetectable null-operation. Granted
> one could see something going on in a machine code or byte code debugger.
> But making that distinction (doing nothing versus self-assignment) at the
> Python level seems, to me, to be meaningless.

There are some circumstances where the subtle distinction matters.
Consider x.y += z where x is an instance of a class that overrides
__setattr__ and __getattribute__ and x.y results in a mutable object.
Not doing the assignment can result in a noticeable difference in
behavior since __setattr__ won't get called. Yes, this is a slightly
obscure case, but it does come up.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list