From 94c212bb22fbfb8072b4c4b55361a9a7c509c133 Mon Sep 17 00:00:00 2001 From: Azat Ibrakov Date: Thu, 14 Nov 2024 03:12:20 +0100 Subject: [PATCH] Fix "Fraction.__int__" magic method --- cfractions/_fractions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cfractions/_fractions.py b/cfractions/_fractions.py index ba18ecd..a4992fc 100644 --- a/cfractions/_fractions.py +++ b/cfractions/_fractions.py @@ -185,8 +185,15 @@ def __gt__(self, other: _Any, /) -> _Any: def __hash__(self, /) -> int: return hash(self._value) - def __int__(self, /) -> int: - return self._value.__int__() + if sys.version_info >= (3, 11): + + def __int__(self, /) -> int: + return self._value.__int__() + + else: + + def __int__(self, /) -> int: + return self.__trunc__() @_overload def __le__(self, other: _Rational | Self, /) -> bool: ...