Sync-up named tuples with the latest version of the ASPN recipe.
Allows optional commas in the field-name spec (help when named tuples are used in conjuction with sql queries).
Adds the __fields__ attribute for introspection and to support conversion to dictionary form.
Adds a __replace__() method similar to str.replace() but using a named field as a target.
Clean-up spelling and presentation in doc-strings.
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index f5dad7d..94015b4 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -30,6 +30,13 @@
self.assertEqual(repr(p), 'Point(x=11, y=22)')
self.assert_('__dict__' not in dir(p)) # verify instance has no dict
self.assert_('__weakref__' not in dir(p))
+ self.assertEqual(p.__fields__, ('x', 'y')) # test __fields__ attribute
+ self.assertEqual(p.__replace__('x', 1), (1, 22)) # test __replace__ method
+
+ # verify that field string can have commas
+ Point = NamedTuple('Point', 'x, y')
+ p = Point(x=11, y=22)
+ self.assertEqual(repr(p), 'Point(x=11, y=22)')
def test_tupleness(self):
Point = NamedTuple('Point', 'x y')