[issue44589] Pattern Matching - duplicate keys in mapping patterns
Brandt Bucher
report at bugs.python.org
Fri Jul 9 13:06:33 EDT 2021
Brandt Bucher <brandtbucher at gmail.com> added the comment:
Nice find! In my opinion, we should do two things here:
- Update PEP 638 to specify that a SyntaxError is raised "if *any duplicate* key patterns are literal patterns". This was absolutely our original intention... I think the nuances were just lost in the final phrasing. I can take care of that PR.
- Update the compiler to raise SyntaxErrors for duplicate literal keys. It should be as simple as updating the first loop in compiler_pattern_mapping to build a set containing the values of any literal keys and raise on duplicates (and adding/updating tests, of course). We'll want to make sure we have test coverage of edge cases like {0: _, False: _}, {0: _, 0.0: _}, {0: _, -0: _}, {0: _, 0j: _}, etc.
Since you found this, you get first dibs on a PR. Otherwise, I have a few first-time contributors who would probably be interested.
----------
nosy: +gvanrossum
type: -> behavior
versions: +Python 3.11 -Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44589>
_______________________________________
More information about the Python-bugs-list
mailing list