Skip to content

enum.Enum type is blindly assigned to "Enum" of other modules #5719

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

Closed
belm0 opened this issue Jan 25, 2022 · 1 comment · Fixed by pylint-dev/astroid#1967
Closed

enum.Enum type is blindly assigned to "Enum" of other modules #5719

belm0 opened this issue Jan 25, 2022 · 1 comment · Fixed by pylint-dev/astroid#1967
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code inference Lib specific 💅 This affect the code from a particular library Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning

Comments

@belm0
Copy link
Contributor

belm0 commented Jan 25, 2022

Bug description

For example, the prometheus_client module has an Enum class. Pylint blindly assumes that references to prometheus_client.Enum are of type enum.Enum, and issues incorrect warnings.

import prometheus_client

_foo_metric = prometheus_client.Enum('foo', 'help text', states=['bar', 'baz'])
_foo_metric.state('bar')  # pylint warning: Instance of 'foo' has no 'state' member

Command used

pylint test.py

Pylint output

************* Module test
test.py:4:0: E1101: Instance of 'foo' has no 'state' member (no-member)

Expected behavior

no warnings

Pylint version

pylint 2.12.1
astroid 2.9.0
Python 3.8.12 (default, Sep 23 2021, 08:42:37)
[Clang 12.0.0 (clang-1200.0.32.29)]

Additional dependencies

prometheus_client==0.8.0

@belm0 belm0 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jan 25, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title enum.Enum type is blindly assigned to "Enum" of other modules enum.Enum type is blindly assigned to "Enum" of other modules Jan 25, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code inference and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 25, 2022
@Pierre-Sassoulas
Copy link
Member

We need to infer the name instead on relying on the name only.

@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning Lib specific 💅 This affect the code from a particular library labels Jul 6, 2022
@DanielNoord DanielNoord added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Sep 3, 2022
mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Jan 14, 2023
… `enum.Enum`. Calls to `Enum` are now inferred & the qualified name is checked.

Refs pylint-dev/pylint#5719
mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Jan 14, 2023
… `enum.Enum`. Calls to `Enum` are now inferred & the qualified name is checked.

Refs pylint-dev/pylint#5719
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code inference Lib specific 💅 This affect the code from a particular library Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants