[issue47079] Integral.denominator shouldn't return an int

Sergey B Kirpichev report at bugs.python.org
Sun Mar 27 06:38:19 EDT 2022


Sergey B Kirpichev <skirpichev at gmail.com> added the comment:

> It does not satisfy your assumptions in msg416056.

Yes, but does it fits to assumptions of the numbers module?  To be fair, there is even no requirement, that numerator/denominator are Integral instances (#25619 address also this).

BTW, it seems, the numpy integer types break my guess that numerator and denominator must have same types (I doubt that anyone uses numbers.Integral defaults, there are no tests for them in the CPython itself):
>>> a = numpy.int8(2); a
2
>>> type(a)
<class 'numpy.int8'>
>>> type(a.numerator)
<class 'numpy.int8'>
>>> type(a.denominator)
<class 'int'>
>>> type(a + a.denominator)
<class 'numpy.int64'>
>>> type(a.denominator + a)
<class 'numpy.int64'>
>>> type(a + a)
<class 'numpy.int8'>

If this is an expected behaviour for Integral types - feel free to close the bugreport.  Looks odd for me, however.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47079>
_______________________________________


More information about the Python-bugs-list mailing list