A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-March/098538.html below:

[Python-Dev] binary operation heuristics -- bug or undocumented?

[Python-Dev] binary operation heuristics -- bug or undocumented?Michael Foord fuzzyman at voidspace.org.uk
Fri Mar 19 14:05:20 CET 2010
On 19/03/2010 12:46, Alex A. Naanou wrote:
> [snip...]
>>>> class C(object):
>>>>          
> ...     def __radd__(self, other):
> ...         print 'C: adding C and %s objects.' % other.__class__.__name__
> ...
>    
>>>> a, b, c = A(), B(), C()
>>>> 1 + c
>>>>          
> C: adding C and int objects.
>
>
>    

That is the whole point of the __radd__ method. ints don't know how to 
add themselves to C objects, so int.__add__ will return NotImplemented 
and then Python will try C.__radd__.

All the best,

Michael

> --uncut--
>
> My first expectation would be to get a TypeError here, as ints indeed
> have an __add__ method, and they do not know anything about C objects
> (obviously :) ). On second thought, giving client code priority to
> handle things has it's merits.
>
> The problem is that I found no mention of this behavior in the docs.
>
>
> P.S. tested in 2.5 through 3.0 and PyPy
>
> Thanks.
>
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4