Overloadable Assignment PEP

Drew Moore drew at astro.pas.rochester.edu
Thu Apr 3 14:02:47 EST 2003


"Daniel Dittmar" <daniel.dittmar at sap.com> wrote in message news:<b6hjle$b4m$1 at news1.wdf.sap-ag.de>...
> Drew Moore wrote:
> > some say in how this takes place. I'm at a loss to explain why
> > the "most trivial case of augmented assignment" was denied this power.
> 
> Performance comes to mind. Assignment is a frequent statement and having to
> search for an __assign__ method will slow things down a lot.
> 
> And if an object has an __assign__ method, how do you perform a real rebind?
> Do we add a 'becomes' operator (similar to the ==/is operators)?
> 
> Daniel

Good points! (and ones I considered)

If the interpreter could tell quickly that the __assign__ method
was in the dictionary (ie, a cached bool flag) the performance
hit would be pretty insignificant, I suspect..

I considered ":=" for the "force name rebind" operator, but don't think
there would be a pressing need for this, would there?

You could always delete the name and reassign it if that is 
what you really needed. The code doing the assign in most
cases would not care about what the assignment did, as
long as the result acted sensibly. Adding a "force rebind" operator
would cause paranoid programmers to use it all the time..
and I don't like the sounds of that. Too messy.

polite __assign__ methods might return the reference to other
rather than self, if they "detected" the need..

Drew




More information about the Python-list mailing list