[Python-ideas] divmod(): fallback to __floordiv__ and __mod__?
Ethan Furman
ethan at stoneleaf.us
Sat Sep 17 18:06:29 EDT 2016
On 09/17/2016 10:57 AM, David Mertz wrote:
> The fallback you described would be a change in the behavior of some
> working programs. Moreover, it would only affect custom classes
> where adding a decorator is an option (even in external code, you
> can use `MyThing = total_divmod(library.MyThing)` under this option.
I'm really not sure what you're saying here, but it sounds like you're
concerned about a __divmod__ overriding existing __mod__ and __floordiv__?
That is not the case. 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 __floordiv__ present? use it
- otherwise, use __divmod__ and return the needed piece
I'm pretty sure __div__ should not fall back to __divmod__.
--
~Ethan~
More information about the Python-ideas
mailing list