[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

[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, r

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

2015-10-16 Thread Sergey Shashkov
Changes by Sergey Shashkov <s...@yandex.ru>: -- hgrepos: -320 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25412> ___ __

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

2015-10-16 Thread Sergey Shashkov
Changes by Sergey Shashkov <s...@yandex.ru>: -- hgrepos: +320 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25412> ___ __

[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 <s...@yandex.ru>: -- hgrepos: +321 keywords: +patch Added file: http://bugs.python.org/file40797/fractions_truediv_fix.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[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 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__. --