[Python-checkins] r69549 - in python/branches/release26-maint: Lib/numbers.py Lib/test/test_fractions.py Misc/NEWS

mark.dickinson python-checkins at python.org
Thu Feb 12 19:05:07 CET 2009


Author: mark.dickinson
Date: Thu Feb 12 19:05:07 2009
New Revision: 69549
Log:
Merged revisions 68813,69546 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk
........
 r68813 | raymond.hettinger | 2009年01月20日 20:34:19 +0000 (2009年1月20日) | 3 lines
 
 Issue 4998: __slots__ on Fractions was useless.
........
 r69546 | mark.dickinson | 2009年02月12日 17:55:42 +0000 (2009年2月12日) | 2 lines
 
 Typo fix.
........
Modified:
 python/branches/release26-maint/ (props changed)
 python/branches/release26-maint/Lib/numbers.py
 python/branches/release26-maint/Lib/test/test_fractions.py
 python/branches/release26-maint/Misc/NEWS
Modified: python/branches/release26-maint/Lib/numbers.py
==============================================================================
--- python/branches/release26-maint/Lib/numbers.py	(original)
+++ python/branches/release26-maint/Lib/numbers.py	Thu Feb 12 19:05:07 2009
@@ -17,6 +17,7 @@
 caring what kind, use isinstance(x, Number).
 """
 __metaclass__ = ABCMeta
+ __slots__ = ()
 
 # Concrete numeric types must provide their own hash implementation
 __hash__ = None
@@ -41,6 +42,8 @@
 type as described below.
 """
 
+ __slots__ = ()
+
 @abstractmethod
 def __complex__(self):
 """Return a builtin complex instance. Called for complex(self)."""
@@ -172,6 +175,8 @@
 Real also provides defaults for the derived operations.
 """
 
+ __slots__ = ()
+
 @abstractmethod
 def __float__(self):
 """Any Real can be converted to a native float object.
@@ -265,6 +270,8 @@
 class Rational(Real):
 """.numerator and .denominator should be in lowest terms."""
 
+ __slots__ = ()
+
 @abstractproperty
 def numerator(self):
 raise NotImplementedError
@@ -288,6 +295,8 @@
 class Integral(Rational):
 """Integral adds a conversion to long and the bit-string operations."""
 
+ __slots__ = ()
+
 @abstractmethod
 def __long__(self):
 """long(self)"""
Modified: python/branches/release26-maint/Lib/test/test_fractions.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_fractions.py	(original)
+++ python/branches/release26-maint/Lib/test/test_fractions.py	Thu Feb 12 19:05:07 2009
@@ -394,6 +394,11 @@
 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)
 
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Thu Feb 12 19:05:07 2009
@@ -80,6 +80,10 @@
 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 #5203: Fixed ctypes segfaults when passing a unicode string to a
 function without argtypes (only occurs if HAVE_USABLE_WCHAR_T is false).
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /