diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-24 19:30:19 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-24 19:30:19 (GMT) |
commit | 5b0e27e50d33f33515f31ff6fec123f5e2be9d73 (patch) | |
tree | 89c7bda9381f616f1cc09c32eaea319b37aa3201 | |
parent | 5ca924038dd196217cedd4b02480ea16acd634f3 (diff) | |
download | cpython-5b0e27e50d33f33515f31ff6fec123f5e2be9d73.zip cpython-5b0e27e50d33f33515f31ff6fec123f5e2be9d73.tar.gz cpython-5b0e27e50d33f33515f31ff6fec123f5e2be9d73.tar.bz2 |
Add support for int(r) just like the other numeric classes.
-rwxr-xr-x | Lib/rational.py | 2 | ||||
-rw-r--r-- | Lib/test/test_rational.py | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/Lib/rational.py b/Lib/rational.py index 60cd129..6824f4a 100755 --- a/Lib/rational.py +++ b/Lib/rational.py @@ -376,6 +376,8 @@ class Rational(RationalAbc): else: return a.numerator // a.denominator + __int__ = __trunc__ + def __floor__(a): """Will be math.floor(a) in 3.0.""" return a.numerator // a.denominator diff --git a/Lib/test/test_rational.py b/Lib/test/test_rational.py index 0f0a48d..3242e43 100644 --- a/Lib/test/test_rational.py +++ b/Lib/test/test_rational.py @@ -160,6 +160,7 @@ class RationalTest(unittest.TestCase): def testConversions(self): self.assertTypedEquals(-1, trunc(R(-11, 10))) + self.assertTypedEquals(-1, int(R(-11, 10))) self.assertTypedEquals(-2, R(-11, 10).__floor__()) self.assertTypedEquals(-1, R(-11, 10).__ceil__()) self.assertTypedEquals(-1, R(-10, 10).__ceil__()) |