[issue44547] fraction.Fraction does not implement __int__.
Michael Amrhein
report at bugs.python.org
Fri Jul 2 09:36:09 EDT 2021
Michael Amrhein <michael at adrhinum.de> added the comment:
The background is an implementation of __pow__ for a fixed-point decimal number:
SupportsIntOrFloat = Union[SupportsInt, SupportsFloat]
def __pow__(self, other: SupportsIntOrFloat, mod: Any = None) -> Complex:
if isinstance(other, SupportsInt):
exp = int(other)
if exp == other:
... handle integer exponent
if isinstance(other, SupportsFloat):
# fractional exponent => fallback to float
return float(self) ** float(other)
return NotImplemented
I came across SupportsInt and SupportsFloat, because they are used in typeshed as param types for int and float.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44547>
_______________________________________
More information about the Python-bugs-list
mailing list