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

SourceForge.net noreply at sourceforge.net
Sun Feb 25 21:10:05 CET 2007


Bugs item #1668540, was opened at 2007-02-25 20:06
Message generated for change (Comment added) made by gbrandl
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: Closed
>Resolution: Invalid
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

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

>Comment By: Georg Brandl (gbrandl)
Date: 2007-02-25 20:10

Message:
Logged In: YES 
user_id=849994
Originator: NO

These special methods are looked up upon the type for new-style classes.
This won't change.

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

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