Message27988
| Author |
zseil |
| Recipients |
| Date |
2006年03月31日.17:19:23 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
The eighth item in that list says:
Exception to the previous item: if the left operand is
an instance of a built-in type or a new-style class,
and the right operand is an instance of a proper
subclass of that type or class, the right operand's
__rop__() method is tried before the left operand's
__op__() method. This is done so that a subclass can
completely override binary operators. Otherwise, the
left operand's __op__ method would always accept the
right operand: when an instance of a given class is
expected, an instance of a subclass of that class is
always acceptable.
This is not correct; subclass's __rop__() method is
called only if it has overloaded the base class's
method; example::
class A(object):
def __add__(self, other):
return self.__class__.__name__
__radd__ = __add__
class B(A):pass
a = A()
b = B()
print b + a # prints B
print a + b # prints A
According to the docs B should be printed in both
cases. The change in behaviour was introduced in
revision 30639. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 14:38:59 | admin | link | issue1462278 messages |
| 2007年08月23日 14:38:59 | admin | create |
|