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/2009-September/092067.html below:

[Python-Dev] operator precedence of __eq__, __ne__, etc, if both object have implementations

[Python-Dev] operator precedence of __eq__, __ne__, etc, if both object have implementationsGuido van Rossum guido at python.org
Thu Sep 24 04:02:43 CEST 2009
On Wed, Sep 23, 2009 at 5:44 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>
>> The interpreter doesn't promise to call those slots with "self" first -
>> self will be the second argument in the "rop" case.
>
> I know. My question is: How does it know whether a subclass
> "has overridden __rop__" when there is no concept of an
> __rop__ method distinct from the __op__ method?

This is a constraint on types implemented in C -- the same definition
is required to apply to __op__ and __rop__.

The datetime module actually has a slight problem here because it
wants to override datetime - timedelta but not timedelta - datetime
(since the latter would have to return a negative time, which is
meaningless). It solves this easily by doing a type check on each
argument and returning Py_NotImplemented for the unimplemented
combinations -- see the various _subtract functions in
Modules/datetimemodule.c. Returning NotImplemented is close enough to
not actually implementing the method.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
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