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/2005-April/052644.html below:

[Python-Dev] New style classes and operator methods

[Python-Dev] New style classes and operator methodsArmin Rigo arigo at tunes.org
Mon Apr 11 22:47:42 CEST 2005
Hi Greg,

On Fri, Apr 08, 2005 at 05:03:42PM +1200, Greg Ewing wrote:
> If the left and right operands are of the same class,
> and the class implements a right operand method but
> not a left operand method, the right operand method
> is not called. Instead, two attempts are made to call
> the left operand method.

This is not a general rule.  The rule is that if both elements are of the same
class, only the non-reversed method is ever called.  The confusing bit is
about having it called twice.  Funnily enough, this only occurs for some
operators (I think only add and mul).  The reason is that internally, the C
core distinguishes about number adding vs sequence concatenation, and number
multiplying vs sequence repetition.  So __add__() and __mul__() are called
twice: once as a numeric computation and as a sequence operation...

Could be fixed with more strange special cases in abstract.c, but I'm not sure
it's worth it.


Armin
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