[New-bugs-announce] [issue2102] New style classes __ror__() operator overloading problem

Wummel report at bugs.python.org
Wed Feb 13 15:51:15 CET 2008

New submission from Wummel:


the attached code in t.py fails to run:
class C (object):
    def __ror__ (self, other):
        return 42
print C() | C()

$ python t.py
Traceback (most recent call last):
  File "t.py", line 5, in ?
    print C() | C()
TypeError: unsupported operand type(s) for |: 'C' and 'C'

If I use old style classes (ie. "class C:" instead of "class
C(object):"), the code runs fine. I suspect that the method lookup for
special operator methods is different in new style classes, but why?
This might also be related to issue #643841 but I am not sure.

components: Interpreter Core
files: t.py
messages: 62361
nosy: calvin
severity: normal
status: open
title: New style classes __ror__()  operator overloading problem
type: behavior
versions: Python 2.4, Python 2.5
Added file: http://bugs.python.org/file9425/t.py

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list