summaryrefslogtreecommitdiffstats
path: root/Lib/fractions.py
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2021-10-21 22:09:47 (GMT)
committerGitHub <noreply@github.com>2021-10-21 22:09:47 (GMT)
commitd1b24775b462f4f28aa4929fd031899170793388 (patch)
treed1df75e96bb817654f96f38a48b98117e2ab570f /Lib/fractions.py
parent51375388bee7287be2d942906b48c8cf3f691e8b (diff)
downloadcpython-d1b24775b462f4f28aa4929fd031899170793388.zip
cpython-d1b24775b462f4f28aa4929fd031899170793388.tar.gz
cpython-d1b24775b462f4f28aa4929fd031899170793388.tar.bz2
bpo-44547: Make Fractions objects instances of typing.SupportsInt (GH-27851)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r--Lib/fractions.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 180cd94..f9ac882 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -594,8 +594,15 @@ class Fraction(numbers.Rational):
"""abs(a)"""
return Fraction(abs(a._numerator), a._denominator, _normalize=False)
+ def __int__(a, _index=operator.index):
+ """int(a)"""
+ if a._numerator < 0:
+ return _index(-(-a._numerator // a._denominator))
+ else:
+ return _index(a._numerator // a._denominator)
+
def __trunc__(a):
- """trunc(a)"""
+ """math.trunc(a)"""
if a._numerator < 0:
return -(-a._numerator // a._denominator)
else: