Sergey Shashkov added the comment:
This patch actually fixes the problem:
https://bugs.python.org/issue35588
https://github.com/python/cpython/commit/3a374e0c5abe805667b71ffaaa7614781101ff4c
from fractions import Fraction
import operator
class Goo:
__radd__, __rdivmod__
New submission from Sergey Shashkov:
__floordiv__ in module fraction fails with TypeError instead of returning
NotImplemented when modulo is a class without __rtruediv__ or __mul__.
Code sample:
class Foo(object):
def __rdivmod__(self, other):
return 'rdivmod works
Sergey Shashkov added the comment:
def __floordiv__(a, b):
"""a // b"""
if isinstance(b, numbers.Complex):
return math.floor(a / b)
else:
return NotImplemented
And the same for __mod__.
--
Sergey Shashkov added the comment:
OK,
then we should not change numbers.py.
And in fractions.py:
def __floordiv__(a, b):
"""a // b"""
if isinstance(b, numbers.Complex) or hasattr(b, '__rtruediv__'):
fr = a
Sergey Shashkov added the comment:
Bad idea, just
def __floordiv__(a, b):
"""a // b"""
if isinstance(b, numbers.Complex):
return math.floor(a / b)
else:
return NotImplemented
If b is inherited from number, real, com
Sergey Shashkov added the comment:
...
def forward(a, b):
if isinstance(b, (int, Fraction)):
return monomorphic_operator(a, b)
elif isinstance(b, float):
return fallback_operator(float(a), b)
elif isinstance(b, complex
Changes by Sergey Shashkov :
--
hgrepos: +320
___
Python tracker
<http://bugs.python.org/issue25412>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Sergey Shashkov :
--
hgrepos: -320
___
Python tracker
<http://bugs.python.org/issue25412>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Sergey Shashkov :
--
hgrepos: +321
keywords: +patch
Added file: http://bugs.python.org/file40797/fractions_truediv_fix.patch
___
Python tracker
<http://bugs.python.org/issue25