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

duplicate-key checker doesn't detect duplicate Enum keys #5150

Closed
Neki opened this issue Oct 13, 2021 · 2 comments · Fixed by #5155
Closed

duplicate-key checker doesn't detect duplicate Enum keys #5150

Neki opened this issue Oct 13, 2021 · 2 comments · Fixed by #5155
Assignees
Labels
Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code Hacktoberfest
Milestone

Comments

@Neki
Copy link

Neki commented Oct 13, 2021

Bug description

The pylint 'duplicate-key' checker doesn't detect duplicate keys when said keys are enum members.

Consider the following code snippet:

from enum import Enum

# shows that the duplicate-key checker is activated, but irrelevant for the actual issue
produces_a_warning = {"key": "value 1", "key": "value 2"}

class MyEnum(Enum):
    KEY = "key"

does_not_produce_a_warning = {MyEnum.KEY: "value 1", MyEnum.KEY: "value 2"}

Running pylint with the default rc file generates only one warning:

duplicate_keys.py:4:21: W0109: Duplicate key 'key' in dictionary (duplicate-key)

pylint should also have detected that the dictionary does_not_produce_a_warning includes a duplicated key.

Configuration

No response

Command used

pylint duplicate_keys.py

Pylint output

************* Module duplicate_keys
duplicate_keys.py:4:21: W0109: Duplicate key 'key' in dictionary (duplicate-key)

Expected behavior

pylint should also have detected that the dictionary does_not_produce_a_warning includes a duplicated key, and should have produced two warnings.

Pylint version

pylint 2.11.1
astroid 2.8.0
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0]

OS / Environment

Ubuntu 20.04

Additional dependencies

No response

@Neki Neki added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 13, 2021
@jaydesl
Copy link
Contributor

jaydesl commented Oct 14, 2021

I think I could help out here!

@Pierre-Sassoulas Pierre-Sassoulas added False Negative 🦋 No message is emitted but something is wrong with the code Hacktoberfest and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 14, 2021
@Pierre-Sassoulas
Copy link
Member

Thanks a lot for offering your help @jaydesl, I assigned you the issue :)

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.12.0 milestone Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code Hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants