[New-bugs-announce] [issue13871] namedtuple does not normalize field names when sanitizing

Jim Jewett report at bugs.python.org
Thu Jan 26 06:47:42 CET 2012


New submission from Jim Jewett <jimjjewett at gmail.com>:

collections.namedtuple raises a ValueError if any of the field names are not valid identifiers, or are duplicates.

It does not normalize the identifiers when checking for duplicates.

(Similar issue with the typename)

>>> namedtuple("dup_fields", ["a", "a"])
Traceback (most recent call last):
  File "<pyshell#23>", line 1, in <module>
    namedtuple("dup_fields", ["a", "a"])
  File "C:\python32\lib\collections.py", line 345, in namedtuple
    raise ValueError('Encountered duplicate field name: %r' % name)
ValueError: Encountered duplicate field name: 'a'



>>> namedtuple("nfk_tester", ["a", "ª"])
Traceback (most recent call last):
  File "<pyshell#22>", line 1, in <module>
    namedtuple("nfk_tester", ["a", "ª"])
  File "C:\python32\lib\collections.py", line 365, in namedtuple
    raise SyntaxError(e.msg + ':\n\n' + class_definition)
  File "<string>", line None
SyntaxError: duplicate argument 'a' in function definition:
...



and 


>>> namedtuple("justª", "ª")
Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    namedtuple("justª", "ª")
  File "C:\python32\lib\collections.py", line 366, in namedtuple
    result = namespace[typename]
KeyError: 'justª'

----------
messages: 151997
nosy: Jim.Jewett
priority: normal
severity: normal
status: open
title: namedtuple does not normalize field names when sanitizing

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13871>
_______________________________________


More information about the New-bugs-announce mailing list