homepage

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: Coercion rules incomplete in Reference Manual
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, zseil
Priority: normal Keywords:

Created on 2006年03月31日 17:19 by zseil, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (2)
msg27988 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2006年03月31日 17:19
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.
msg27989 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006年04月01日 07:23
Logged In: YES 
user_id=849994
Thanks, fixed in rev. 43521, 43522.
History
Date User Action Args
2022年04月11日 14:56:16adminsetgithub: 43127
2006年03月31日 17:19:23zseilcreate

AltStyle によって変換されたページ (->オリジナル) /