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

This commit is contained in:
Raymond Hettinger 2016-08-16 10:55:43 -07:00
parent 3ee933f1c3
commit 6538b430cf
4 changed files with 22 additions and 3 deletions

View file

@ -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_keyword_only_arguments(self):
# See issue 25628
with support.captured_stdout() as template:
NT = namedtuple('NT', ['x', 'y'], verbose=True)
self.assertIn('class NT', NT._source)
with self.assertRaises(TypeError):
NT = namedtuple('NT', ['x', 'y'], True)
NT = namedtuple('NT', ['abc', 'def'], rename=True)
self.assertEqual(NT._fields, ('abc', '_1'))
with self.assertRaises(TypeError):
NT = namedtuple('NT', ['abc', 'def'], False, True)
def test_namedtuple_subclass_issue_24931(self):
class Point(namedtuple('_Point', ['x', 'y'])):