diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-24 18:05:54 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-24 18:05:54 (GMT) |
commit | 7a6eacd2ca6322640ca99adbeeed6a134ed7009a (patch) | |
tree | 0caa177d870c3d6b7f67c65c5cd29a8c0460c97b | |
parent | 37edeab77875ef35ea54b92d5ba8a94df7deb3f7 (diff) | |
download | cpython-7a6eacd2ca6322640ca99adbeeed6a134ed7009a.zip cpython-7a6eacd2ca6322640ca99adbeeed6a134ed7009a.tar.gz cpython-7a6eacd2ca6322640ca99adbeeed6a134ed7009a.tar.bz2 |
Clean-up and speed-up code by accessing numerator/denominator directly. There's no reason to enforce readonliness
-rwxr-xr-x | Lib/rational.py | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/Lib/rational.py b/Lib/rational.py index e34a713..60cd129 100755 --- a/Lib/rational.py +++ b/Lib/rational.py @@ -94,7 +94,7 @@ class Rational(RationalAbc): """ - __slots__ = ('_numerator', '_denominator') + __slots__ = ('numerator', 'denominator') # We're immutable, so use __new__ not __init__ def __new__(cls, numerator=0, denominator=1): @@ -134,8 +134,8 @@ class Rational(RationalAbc): raise ZeroDivisionError('Rational(%s, 0)' % numerator) g = _gcd(numerator, denominator) - self._numerator = int(numerator // g) - self._denominator = int(denominator // g) + self.numerator = int(numerator // g) + self.denominator = int(denominator // g) return self @classmethod @@ -208,14 +208,6 @@ class Rational(RationalAbc): result = new return result - @property - def numerator(a): - return a._numerator - - @property - def denominator(a): - return a._denominator - def __repr__(self): """repr(self)""" return ('Rational(%r,%r)' % (self.numerator, self.denominator)) |