[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2019-01-11 Thread Sergey Shashkov
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__,

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Sergey Shashkov
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 / b if fr != NotImplemented:

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Sergey Shashkov
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, complex, Fraction and etc, then a

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Oscar Benjamin
Oscar Benjamin added the comment: You should test the change with number types that don't use the number tower e.g. Decimal, sympy, gmpy2, mpf, numpy arrays etc. Few non stdlib types use the number ABCs so testing against numbers.Complex may cause a change in behaviour. -- nosy:

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Sergey Shashkov
Changes by Sergey Shashkov : -- hgrepos: -320 ___ Python tracker ___ ___ Python-bugs-list

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Sergey Shashkov
Changes by Sergey Shashkov : -- hgrepos: +320 ___ Python tracker ___ ___ Python-bugs-list

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Sergey Shashkov
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):

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-16 Thread Sergey Shashkov
Changes by Sergey Shashkov : -- hgrepos: +321 keywords: +patch Added file: http://bugs.python.org/file40797/fractions_truediv_fix.patch ___ Python tracker

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-15 Thread Sergey Shashkov
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' from

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-15 Thread STINNER Victor
STINNER Victor added the comment: Can you please write a patch? See https://docs.python.org/devguide/ -- nosy: +haypo ___ Python tracker ___

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-15 Thread R. David Murray
Changes by R. David Murray : -- nosy: +mark.dickinson ___ Python tracker ___ ___

[issue25412] __floordiv__ in module fraction fails with TypeError instead of returning NotImplemented

2015-10-15 Thread Sergey Shashkov
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__. -- ___ Python