This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: namedtuple does not normalize field names when checking for duplicates
Type: Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Jim.Jewett, rhettinger
Priority: low Keywords:

Created on 2012-01-26 05:47 by Jim.Jewett, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg151997 - (view) Author: Jim Jewett (Jim.Jewett) * (Python triager) Date: 2012-01-26 05:47
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ª'
msg151998 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-01-26 07:48
The SyntaxError is fine.  The dupcheck isn't about sanitization anyway; rather, it was part of a suite of tests designed to add a more helpful error messages than the usual ones you get if you had rolled a class by hand.  I would close as "invalid" but want to think it over for a while -- we'll see how all your other normalization "bugs" resolve.
msg192923 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-07-12 06:30
Closing this for the reasons listed above.
History
Date User Action Args
2022-04-11 14:57:26adminsetgithub: 58079
2013-07-12 06:30:34rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg192923
2012-01-26 07:54:29rhettingersettitle: namedtuple does not normalize field names when sanitizing -> namedtuple does not normalize field names when checking for duplicates
2012-01-26 07:48:55rhettingersetmessages: + msg151998
2012-01-26 07:32:18rhettingersetpriority: normal -> low
assignee: rhettinger

nosy: + rhettinger
2012-01-26 05:47:41Jim.Jewettcreate