[ python-Bugs-1462278 ] Coercion rules incomplete in Reference Manual

SourceForge.net noreply at sourceforge.net
Sat Apr 1 09:23:25 CEST 2006


Bugs item #1462278, was opened at 2006-03-31 17:19
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1462278&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: Documentation
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Žiga Seilnacht (zseil)
Assigned to: Nobody/Anonymous (nobody)
Summary: Coercion rules incomplete in Reference Manual

Initial Comment:
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.

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

>Comment By: Georg Brandl (gbrandl)
Date: 2006-04-01 07:23

Message:
Logged In: YES 
user_id=849994

Thanks, fixed in rev. 43521, 43522.

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1462278&group_id=5470


More information about the Python-bugs-list mailing list