Skip to content
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

Closed
jimjjewett mannequin opened this issue Jan 26, 2012 · 3 comments
Closed

namedtuple does not normalize field names when checking for duplicates #58079

jimjjewett mannequin opened this issue Jan 26, 2012 · 3 comments
Assignees

Comments

@jimjjewett
Copy link
Mannequin

jimjjewett mannequin commented Jan 26, 2012

BPO 13871
Nosy @rhettinger, @JimJJewett

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:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2013-07-12.06:30:34.297>
created_at = <Date 2012-01-26.05:47:41.903>
labels = ['invalid']
title = 'namedtuple does not normalize field names when checking for duplicates'
updated_at = <Date 2013-07-12.06:30:34.296>
user = 'https://github.com/JimJJewett'

bugs.python.org fields:

activity = <Date 2013-07-12.06:30:34.296>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2013-07-12.06:30:34.297>
closer = 'rhettinger'
components = []
creation = <Date 2012-01-26.05:47:41.903>
creator = 'Jim.Jewett'
dependencies = []
files = []
hgrepos = []
issue_num = 13871
keywords = []
message_count = 3.0
messages = ['151997', '151998', '192923']
nosy_count = 2.0
nosy_names = ['rhettinger', 'Jim.Jewett']
pr_nums = []
priority = 'low'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue13871'
versions = []

@jimjjewett
Copy link
Mannequin Author

jimjjewett mannequin commented Jan 26, 2012

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ª'

@rhettinger rhettinger self-assigned this Jan 26, 2012
@rhettinger
Copy link
Contributor

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.

@rhettinger rhettinger changed the title namedtuple does not normalize field names when sanitizing namedtuple does not normalize field names when checking for duplicates Jan 26, 2012
@rhettinger
Copy link
Contributor

Closing this for the reasons listed above.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant