From 7a6eacd2ca6322640ca99adbeeed6a134ed7009a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 24 Jan 2008 18:05:54 +0000 Subject: [PATCH] Clean-up and speed-up code by accessing numerator/denominator directly. There's no reason to enforce readonliness --- Lib/rational.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Lib/rational.py b/Lib/rational.py index e34a713440..60cd129946 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)) -- 2.50.1