Re: [Python-ideas] divmod(): fallback to __floordiv__ and __mod__?

2016-09-18 Thread Steven D'Aprano
On Sat, Sep 17, 2016 at 09:01:53AM +, Spencer Brown wrote: > Currently, calling divmod() on a class with __floordiv__ and __mod__ > defined, but not __divmod__ raises a TypeError. Is there any reason > why it doesn't fallback to (self // x, self % x)? Because things get really complex,

Re: [Python-ideas] divmod(): fallback to __floordiv__ and __mod__?

2016-09-17 Thread Ethan Furman
On 09/17/2016 03:14 PM, Chris Angelico wrote: On Sun, Sep 18, 2016 at 8:06 AM, Ethan Furman wrote: Just like Python will use the defined __ne__ if it's present, or fall back to negating the result of __eq__ if __ne__ is not present, I see __divmod__ working the same way: - is __mod__

Re: [Python-ideas] divmod(): fallback to __floordiv__ and __mod__?

2016-09-17 Thread Chris Angelico
On Sun, Sep 18, 2016 at 8:06 AM, Ethan Furman wrote: > Just like Python will use the defined __ne__ if > it's present, or fall back to negating the result of __eq__ if __ne__ is > not present, I see __divmod__ working the same way: > > - is __mod__ present? use it > - is

Re: [Python-ideas] divmod(): fallback to __floordiv__ and __mod__?

2016-09-17 Thread Chris Angelico
On Sun, Sep 18, 2016 at 3:57 AM, David Mertz wrote: > For example, '%' is fairly widely (ab)used for meanings other than modulo. > E.g. string formatting. Probably not that many classes that respond to '%' > to do something non-modulo simultaneously implement `.__divmod__()` ...

Re: [Python-ideas] divmod(): fallback to __floordiv__ and __mod__?

2016-09-17 Thread David Mertz
It seems like this could be something similar to `functools.total_ordering` and decorate a class. In principle that transformation could go in either direction, but only if the decorator is used. On Sat, Sep 17, 2016 at 3:56 AM, Mark Dickinson wrote: > On Sat, Sep 17, 2016