cpython: f086d6c9d9f6 (original) (raw)

Mercurial > cpython

changeset 102703:f086d6c9d9f6

Issue #25628: Make namedtuple "rename" and "verbose" parameters keyword-only. [#25628]

Raymond Hettinger python@rcn.com
date Tue, 16 Aug 2016 10:55:43 -0700
parents ad141164c792
children 61403b862793
files Doc/library/collections.rst Lib/collections/__init__.py Lib/test/test_collections.py Misc/NEWS
diffstat 4 files changed, 22 insertions(+), 3 deletions(-)[+] [-] Doc/library/collections.rst 8 Lib/collections/__init__.py 2 Lib/test/test_collections.py 12 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -763,7 +763,7 @@ Named tuples assign meaning to each posi 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=False, rename=False) +.. function:: namedtuple(typename, field_names, *, verbose=False, rename=False) 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 @@ -799,7 +799,11 @@ they add the ability to access fields by a namedtuple. .. versionchanged:: 3.1

+

.. doctest::

--- a/Lib/collections/init.py +++ b/Lib/collections/init.py @@ -353,7 +353,7 @@ class {typename}(tuple): {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}') ''' -def namedtuple(typename, field_names, verbose=False, rename=False): +def namedtuple(typename, field_names, *, verbose=False, rename=False): """Returns a new subclass of tuple with named fields. >>> Point = namedtuple('Point', ['x', 'y'])

--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -412,6 +412,18 @@ class TestNamedTuple(unittest.TestCase): self.assertEqual(NTColor._fields, ('red', 'green', 'blue')) globals().pop('NTColor', None) # clean-up after this test

+

def test_namedtuple_subclass_issue_24931(self): class Point(namedtuple('_Point', ['x', 'y'])):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -73,6 +73,9 @@ Library to ref count problem introduced in code for Issue #27038 in 3.6.0a3. Patch by Xiang Zhang. +- Issue #25628: The verbose and rename parameters for collections.namedtuple