diff options
author | Raymond Hettinger <python@rcn.com> | 2011-06-03 06:49:44 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-06-03 06:49:44 (GMT) |
commit | 22cc1183a3d92a29836de3c79f5e7b099e39c1f1 (patch) | |
tree | a12ef73f049e6500c0163af02dbfbf6705632c14 /Lib | |
parent | acf71b89ffee503874178720dfb98b1651047891 (diff) | |
parent | 3d89057ff80261e8960420305b432cd9783bb4e2 (diff) | |
download | cpython-22cc1183a3d92a29836de3c79f5e7b099e39c1f1.zip cpython-22cc1183a3d92a29836de3c79f5e7b099e39c1f1.tar.gz cpython-22cc1183a3d92a29836de3c79f5e7b099e39c1f1.tar.bz2 |
merge
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/collections/__init__.py | 2 | ||||
-rw-r--r-- | Lib/test/test_collections.py | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 4b447ac..03bd2b3 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -269,6 +269,8 @@ class {typename}(tuple): 'Return a new OrderedDict which maps field names to their values' return OrderedDict(zip(self._fields, self)) + __dict__ = property(_asdict) + 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)) diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index f1f1094..eb6d4d7 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -181,12 +181,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 self.assertNotIn('__weakref__', dir(p)) self.assertEqual(p, Point._make([11, 22])) # test _make classmethod self.assertEqual(p._fields, ('x', 'y')) # test _fields attribute self.assertEqual(p._replace(x=1), (1, 22)) # test _replace method self.assertEqual(p._asdict(), dict(x=11, y=22)) # test _asdict method + self.assertEqual(vars(p), p._asdict()) # verify that vars() works try: p._replace(x=1, error=2) |