]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 69547 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Thu, 12 Feb 2009 18:00:48 +0000 (18:00 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Thu, 12 Feb 2009 18:00:48 +0000 (18:00 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r69547 | mark.dickinson | 2009-02-12 17:58:36 +0000 (Thu, 12 Feb 2009) | 3 lines

  Issue 4998: restore utility of __slots__ on Fraction.
  (forward merge of r68813).
........

Lib/numbers.py
Lib/test/test_fractions.py
Misc/NEWS

index 827c25379ff8cb21f06310b9f956cd3451c1be09..82960f04cea276da84890435156a7810b554a672 100644 (file)
@@ -15,6 +15,8 @@ class Number(metaclass=ABCMeta):
     If you just want to check if an argument x is a number, without
     caring what kind, use isinstance(x, Number).
     """
+    __slots__ = ()
+
     # Concrete numeric types must provide their own hash implementation
     __hash__ = None
 
@@ -38,6 +40,8 @@ class Complex(Number):
     type as described below.
     """
 
+    __slots__ = ()
+
     @abstractmethod
     def __complex__(self):
         """Return a builtin complex instance. Called for complex(self)."""
@@ -152,6 +156,8 @@ class Real(Complex):
     Real also provides defaults for the derived operations.
     """
 
+    __slots__ = ()
+
     @abstractmethod
     def __float__(self):
         """Any Real can be converted to a native float object.
@@ -264,6 +270,8 @@ Real.register(float)
 class Rational(Real):
     """.numerator and .denominator should be in lowest terms."""
 
+    __slots__ = ()
+
     @abstractproperty
     def numerator(self):
         raise NotImplementedError
@@ -287,6 +295,8 @@ class Rational(Real):
 class Integral(Rational):
     """Integral adds a conversion to int and the bit-string operations."""
 
+    __slots__ = ()
+
     @abstractmethod
     def __int__(self):
         """int(self)"""
index 6851d2d31325970fede57af8f0f068e454e2ef99..91fcd26d5c9cc42f598ba49661d79b66a5e31a5c 100644 (file)
@@ -407,6 +407,11 @@ class FractionTest(unittest.TestCase):
         self.assertEqual(id(r), id(copy(r)))
         self.assertEqual(id(r), id(deepcopy(r)))
 
+    def test_slots(self):
+        # Issue 4998
+        r = F(13, 7)
+        self.assertRaises(AttributeError, setattr, r, 'a', 10)
+
 def test_main():
     run_unittest(FractionTest, GcdTest)
 
index cd01803ee81b6955da4ede49a0a8a5f245befb3a..8e3570a1e51edeecd55086b381b66d319e68265b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -116,6 +116,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #4998: The memory saving effect of __slots__ had been lost on Fractions
+  which inherited from numbers.py which did not have __slots__ defined.  The
+  numbers hierarchy now has its own __slots__ declarations.
+
 - Issue #4631: Fix urlopen() result when an HTTP response uses chunked
   encoding.