Commits

Mark Dickinson committed 5d28405

Merged revisions 69547 via svnmerge from
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).
........

  • Participants
  • Parent commits acdb323
  • Branches 3.0

Comments (0)

Files changed (3)

     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
 
     type as described below.
     """
 
+    __slots__ = ()
+
     @abstractmethod
     def __complex__(self):
         """Return a builtin complex instance. Called for complex(self)."""
     Real also provides defaults for the derived operations.
     """
 
+    __slots__ = ()
+
     @abstractmethod
     def __float__(self):
         """Any Real can be converted to a native float object.
 class Rational(Real):
     """.numerator and .denominator should be in lowest terms."""
 
+    __slots__ = ()
+
     @abstractproperty
     def numerator(self):
         raise NotImplementedError
 class Integral(Rational):
     """Integral adds a conversion to int and the bit-string operations."""
 
+    __slots__ = ()
+
     @abstractmethod
     def __int__(self):
         """int(self)"""

Lib/test/test_fractions.py

         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)
 
 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.