[Python-checkins] cpython (merge 3.4 -> 3.5): merge
raymond.hettinger
python-checkins at python.org
Sun Aug 30 18:17:08 CEST 2015
https://hg.python.org/cpython/rev/55bd86b0e333
changeset: 97551:55bd86b0e333
branch: 3.5
parent: 97548:192c654a7c93
parent: 97550:fa3ac31cfa44
user: Raymond Hettinger <python at rcn.com>
date: Sun Aug 30 09:15:36 2015 -0700
summary:
merge
files:
Doc/library/collections.rst | 6 +++---
Lib/collections/__init__.py | 11 +----------
Lib/test/test_collections.py | 12 +++++++++++-
3 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -842,10 +842,10 @@
.. method:: somenamedtuple._asdict()
Return a new :class:`OrderedDict` which maps field names to their corresponding
- values. Note, this method is no longer needed now that the same effect can
- be achieved by using the built-in :func:`vars` function::
+ values::
- >>> vars(p)
+ >>> p = Point(x=11, y=22)
+ >>> p._asdict()
OrderedDict([('x', 11), ('y', 22)])
.. versionchanged:: 3.1
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -320,23 +320,14 @@
'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
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -257,7 +257,6 @@
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 @@
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
################################################################################
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list