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) *  |
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) *  |
Date: 2018-06-16 18:10 |
See issue 33881 for the corresponding dataclasses issue. |
|
|
msg319771 - (view) |
Author: Eric V. Smith (eric.smith) *  |
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) *  |
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) *  |
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) *  |
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. |
|
|