[Python-checkins] r71074 - in python/branches/py3k/Lib: collections.py test/test_collections.py

raymond.hettinger python-checkins at python.org
Fri Apr 3 00:31:59 CEST 2009


Author: raymond.hettinger
Date: Fri Apr  3 00:31:59 2009
New Revision: 71074

Log:
Have namedtuple's field renamer assign names that
are consistent with the corresponding tuple index.



Modified:
   python/branches/py3k/Lib/collections.py
   python/branches/py3k/Lib/test/test_collections.py

Modified: python/branches/py3k/Lib/collections.py
==============================================================================
--- python/branches/py3k/Lib/collections.py	(original)
+++ python/branches/py3k/Lib/collections.py	Fri Apr  3 00:31:59 2009
@@ -174,7 +174,7 @@
             if (not all(c.isalnum() or c=='_' for c in name) or _iskeyword(name)
                 or not name or name[0].isdigit() or name.startswith('_')
                 or name in seen):
-                names[i] = '_%d' % (i+1)
+                names[i] = '_%d' % i
             seen.add(name)
         field_names = tuple(names)
     for name in (typename,) + field_names:

Modified: python/branches/py3k/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k/Lib/test/test_collections.py	(original)
+++ python/branches/py3k/Lib/test/test_collections.py	Fri Apr  3 00:31:59 2009
@@ -51,12 +51,12 @@
 
     def test_name_fixer(self):
         for spec, renamed in [
-            [('efg', 'g%hi'),  ('efg', '_2')],                              # field with non-alpha char
-            [('abc', 'class'), ('abc', '_2')],                              # field has keyword
-            [('8efg', '9ghi'), ('_1', '_2')],                               # field starts with digit
-            [('abc', '_efg'), ('abc', '_2')],                               # field with leading underscore
-            [('abc', 'efg', 'efg', 'ghi'), ('abc', 'efg', '_3', 'ghi')],    # duplicate field
-            [('abc', '', 'x'), ('abc', '_2', 'x')],                         # fieldname is a space
+            [('efg', 'g%hi'),  ('efg', '_1')],                              # field with non-alpha char
+            [('abc', 'class'), ('abc', '_1')],                              # field has keyword
+            [('8efg', '9ghi'), ('_0', '_1')],                               # field starts with digit
+            [('abc', '_efg'), ('abc', '_1')],                               # field with leading underscore
+            [('abc', 'efg', 'efg', 'ghi'), ('abc', 'efg', '_2', 'ghi')],    # duplicate field
+            [('abc', '', 'x'), ('abc', '_1', 'x')],                         # fieldname is a space
         ]:
             self.assertEqual(namedtuple('NT', spec, rename=True)._fields, renamed)
 


More information about the Python-checkins mailing list