On Wed, Sep 23, 2009 at 5:44 PM, Greg Ewing <greg.ew...@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/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com