This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: I can't change attribute __op__ in new-style classes
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, netimen
Priority: normal Keywords:

Created on 2007-02-25 20:06 by netimen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
operator.py netimen, 2007-02-25 20:06 code example
Messages (3)
msg31348 - (view) Author: netimen (netimen) Date: 2007-02-25 20:06
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
msg31349 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-02-25 20:10
These special methods are looked up upon the type for new-style classes. This won't change.
msg31350 - (view) Author: netimen (netimen) Date: 2007-02-25 22:02
But.. then how to overload operators&
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44616
2007-02-25 20:06:23netimencreate