diff options
| author | Raymond Hettinger <python@rcn.com> | 2015-08-30 09:15:36 -0700 |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2015-08-30 09:15:36 -0700 |
| commit | 9157545c1179045dda9d3c23961a971d838afa3a (patch) | |
| tree | 5f90ae18edb1e9d1ae563e1c57fb598a26fe4f6b /Lib | |
| parent | ce50802679bd4742f604c92775cd4f6b448769ea (diff) | |
| parent | 7a3602e7cf1c0f54d52c563afca50c2e09e7bbf9 (diff) | |
| download | cpython-git-9157545c1179045dda9d3c23961a971d838afa3a.tar.gz | |
merge
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/collections/__init__.py | 11 | ||||
| -rw-r--r-- | Lib/test/test_collections.py | 12 |
2 files changed, 12 insertions, 11 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 80dc4f6d4e..26e5d34716 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -320,23 +320,14 @@ class {typename}(tuple): 'Return a nicely formatted representation string' return self.__class__.__name__ + '({repr_fmt})' % self - @property - def __dict__(self): - 'A new OrderedDict mapping field names to their values' - return OrderedDict(zip(self._fields, self)) - def _asdict(self): 'Return a new OrderedDict which maps field names to their values.' - return self.__dict__ + return OrderedDict(zip(self._fields, self)) def __getnewargs__(self): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) - def __getstate__(self): - 'Exclude the OrderedDict from pickling' - return None - {field_defs} """ diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index c2d03eea74..4124f91e15 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -257,7 +257,6 @@ class TestNamedTuple(unittest.TestCase): 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) @@ -412,6 +411,17 @@ class TestNamedTuple(unittest.TestCase): globals().pop('NTColor', None) # clean-up after this test + def test_namedtuple_subclass_issue_24931(self): + class Point(namedtuple('_Point', ['x', 'y'])): + pass + + a = Point(3, 4) + self.assertEqual(a._asdict(), OrderedDict([('x', 3), ('y', 4)])) + + a.w = 5 + self.assertEqual(a.__dict__, {'w': 5}) + + ################################################################################ ### Abstract Base Classes ################################################################################ |
