Issue 1818: collections.namedtuple() to support automatic renaming of invalid fieldnames.
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 6aaeb13..94fd16c 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -617,7 +617,7 @@
self-documenting code. They can be used wherever regular tuples are used, and
they add the ability to access fields by name instead of position index.
-.. function:: namedtuple(typename, field_names, [verbose])
+.. function:: namedtuple(typename, field_names, [verbose], [rename])
Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessible by attribute lookup as
@@ -635,6 +635,11 @@
a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*,
or *raise*.
+ If *rename* is true, invalid fieldnames are automatically replaced
+ with positional names. For example, ``['abc', 'def', 'ghi', 'abc']`` is
+ converted to ``['abc', '_2', 'ghi', '_4']``, eliminating the keyword
+ ``def`` and the duplicate fieldname ``abc``.
+
If *verbose* is true, the class definition is printed just before being built.
Named tuple instances do not have per-instance dictionaries, so they are
@@ -642,6 +647,9 @@
.. versionadded:: 2.6
+ .. versionchanged:: 2.7
+ added support for *rename*.
+
Example:
.. doctest::