cpython: 18303391b981 (original) (raw)
Mercurial > cpython
changeset 83591:18303391b981 2.7
Issue #15535: Fix regression in pickling of named tuples. [#15535]
Raymond Hettinger python@rcn.com | |
---|---|
date | Fri, 03 May 2013 00:59:20 -0700 |
parents | c3656dca65e7 |
children | 26068bfec70e |
files | Doc/library/collections.rst Lib/collections.py Lib/test/test_collections.py Misc/NEWS |
diffstat | 4 files changed, 5 insertions(+), 6 deletions(-)[+] [-] Doc/library/collections.rst 4 Lib/collections.py 2 Lib/test/test_collections.py 2 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -628,9 +628,7 @@ Example: 'Return a new OrderedDict which maps field names to their values' return OrderedDict(zip(self._fields, self))
def _replace(_self, **kwds):[](#l1.10) 'Return a new Point object replacing specified fields with new values'[](#l1.11) result = _self._make(map(kwds.pop, ('x', 'y'), _self))[](#l1.12) if kwds:[](#l1.13)
--- a/Lib/collections.py +++ b/Lib/collections.py @@ -259,8 +259,6 @@ class {typename}(tuple): 'Return a new OrderedDict which maps field names to their values' return OrderedDict(zip(self._fields, self))
- def _replace(_self, **kwds): 'Return a new {typename} object replacing specified fields with new values' result = _self._make(map(kwds.pop, {field_names!r}, _self))
--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -78,12 +78,12 @@ class TestNamedTuple(unittest.TestCase): self.assertRaises(TypeError, eval, 'Point(XXX=1, y=2)', locals()) # wrong keyword argument self.assertRaises(TypeError, eval, 'Point(x=1)', locals()) # missing keyword argument self.assertEqual(repr(p), 'Point(x=11, y=22)')
self.assertNotIn('__dict__', dir(p)) # verify instance has no dict[](#l3.7) self.assertNotIn('__weakref__', dir(p))[](#l3.8) self.assertEqual(p, Point._make([11, 22])) # test _make classmethod[](#l3.9) self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute[](#l3.10) self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method[](#l3.11) self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method[](#l3.12)
self.assertEqual(vars(p), p._asdict()) # verify that vars() works[](#l3.13)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -17,6 +17,9 @@ Build Core and Builtins ----------------- +- Issue #15535: Fixed regression in the pickling of named tuples by