New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
namedtuple does not normalize field names when checking for duplicates #58079
Comments
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ª' |
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. |
Closing this for the reasons listed above. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: