[Python-checkins] cpython (merge 3.2 -> default): merge

raymond.hettinger python-checkins at python.org
Fri Jun 3 08:50:23 CEST 2011


http://hg.python.org/cpython/rev/94cfd8a5df11
changeset:   70610:94cfd8a5df11
parent:      70607:475bb98ae813
parent:      70609:40ad90580935
user:        Raymond Hettinger <python at rcn.com>
date:        Thu Jun 02 23:49:44 2011 -0700
summary:
  merge

files:
  Lib/collections/__init__.py  |  2 ++
  Lib/test/test_collections.py |  2 +-
  Misc/NEWS                    |  2 ++
  3 files changed, 5 insertions(+), 1 deletions(-)


diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -269,6 +269,8 @@
         '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
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -181,12 +181,12 @@
         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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -188,6 +188,8 @@
   pydoc, tkinter, and xml.parsers.expat. This were useless version constants
   left over from the Mercurial transition
 
+- Named tuples now work correctly with vars().
+
 - Issue #12085: Fix an attribute error in subprocess.Popen destructor if the
   constructor has failed, e.g. because of an undeclared keyword argument. Patch
   written by Oleg Oshmyan.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list