[ python-Bugs-1668540 ] I can't change attribute __op__ in new-style classes

SourceForge.net noreply at sourceforge.net
Sun Feb 25 21:06:23 CET 2007


Bugs item #1668540, was opened at 2007-02-25 23:06
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1668540&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Type/class unification
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: netimen (netimen)
Assigned to: Nobody/Anonymous (nobody)
Summary: I can't change attribute __op__ in new-style classes

Initial Comment:
I tried to use multimethod module from peers package available at http://viral.media.mit.edu/peers/peers-0.20050929.tar.gz to create several __mul__ operators in a new-style class and experienced this problem.

In new-style class I can't change the attribute __op__. Even if I change it with setattr, genuine __op__ will be called.

For instance, if I set __mul__ operator to method object new_mul and write

setattr(obj, '__mul__', new_mul)
obj *= 1 # __mul__ will be called.
# But
obj.__mul__(1) # new_mul will be called.

With common methods and with old-style classes all works properly.

P.S. Sorry for my English

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1668540&group_id=5470


More information about the Python-bugs-list mailing list