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 should use NFKD to find duplicate members
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, John Cooke, eric.smith, rhettinger
Priority: normal Keywords:

Created on 2018-06-16 17:12 by John Cooke, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg319763 - (view) Author: John Cooke (John Cooke) Date: 2018-06-16 17:12
from collections import namedtuple
# create a namedtuple whose members are:
# 00B5;MICRO SIGN;Ll;
# 03BC;GREEK SMALL LETTER MU;Ll
# these are both legal identifier names
names = ['\u00b5', '\u03bc']
for name in names:
    assert name.isidentifier()
mu = namedtuple('mu', names)

# should have raised ValueError, but instead get SyntaxError
msg319765 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-16 17:59
Not that it really matters to this issue, but here's how dataclasses and attrs deal with this:

dataclasses has the same issue, via make_dataclass().

attrs gives a syntax error with your field names, but interestingly this succeeds:

>>> Foo = attr,make_class('Foo', ['a', 'b', 'a'])
>>> Foo(1, 3)

I'll open a corresponding issue for dataclasses.
Foo(a=1, b=3)
msg319767 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-16 18:10
See issue 33881 for the corresponding dataclasses issue.
msg319771 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-16 18:21
Actually, should this be NKFC?

From https://docs.python.org/3.6/reference/lexical_analysis.html#identifiers : 

"All identifiers are converted into the normal form NFKC while parsing; comparison of identifiers is based on NFKC."
msg319851 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-06-18 02:25
Of late, people have been very concerned with namedtuple construction time, so I'm disinclined to add this overhead for something that doesn't seem to have been a problem in the real world.

Also, the SyntaxError seems reasonable.  That is the same error given by a regular function definition or types.SimpleNamespace:

    >>> def f(µ=1, μ=2):
    	    pass
    SyntaxError: duplicate argument 'μ' in function definition

    >>> SimpleNamespace(µ=1, μ=2)
    SyntaxError: keyword argument repeated
msg357996 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-12-08 08:47
Hey @rhettinger, what is the status of this issue? Is there a consensus about fixing it or can this issue be closed?
msg358013 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-12-08 17:51
Marking as closed for the reasons listed above.

Other thoughts:
* In the class form with types.NamedTuple, no error is raised.
* In the function form with collections.namedtuple, the various
  TypeErrors and ValueErrors are just courtesy checks
  intended to provide slightly nicer error messages when possible.
  It wasn't the goal to upstage all possible syntax errors.
History
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 78061
2019-12-08 17:51:19rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg358013

stage: resolved
2019-12-08 08:47:20BTaskayasetnosy: + BTaskaya
messages: + msg357996
2018-06-18 02:25:28rhettingersetmessages: + msg319851
2018-06-16 18:21:51eric.smithsetmessages: + msg319771
2018-06-16 18:10:49eric.smithsetnosy: + rhettinger
messages: + msg319767
2018-06-16 17:59:31eric.smithsetnosy: + eric.smith
messages: + msg319765
2018-06-16 17:12:33John Cookecreate