[Python-ideas] dictionary constructor should not allow duplicate keys
Pavol Lisy
pavol.lisy at gmail.com
Wed May 4 02:47:00 EDT 2016
2016-05-04 6:03 GMT+02:00, Nick Coghlan <ncoghlan at gmail.com>:
> I was curious as to whether or not it was technically feasible to
> implement this "duplicate keys" check solely for dict displays in
> CPython without impacting other dict use cases, and it turns out it
> should be.
[...]
> 1. Report a DeprecationWarning in 3.6
> 2. Report a [RuntimeError? ValueError?] in 3.7+
But what about SyntaxError instead of RuntimeError? Could it be easily
done too?
PS.
Probably nobody is interested in my tests with unicode literals which
are "NFKC equivalent" but it help me to understand how things are done
behind the scene.
def f(**kwd):
for i in kwd:
print(i, kwd[i])
def tst():
f(ij=1, ij=2) # this is syntax error
def tst2():
f(**{1:1}) # this is runtime error
def tst3():
f(**{'ij':1, 'ij':2}) # this is legal (for me a little unexpected,
maybe bug?)
More information about the Python-ideas
mailing list