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

False positive no-member for enum.Enum's _value2member_map_. #3941

Closed
jamesbraza opened this issue Nov 10, 2020 · 7 comments
Closed

False positive no-member for enum.Enum's _value2member_map_. #3941

jamesbraza opened this issue Nov 10, 2020 · 7 comments
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@jamesbraza
Copy link

Steps to reproduce

Here's a minimal repro:

"""Show that pylint doesn't see enum's _value2member_map_."""

from enum import Enum


class Foo(Enum):
    """Enum class whose values we care about."""

    BAR = 0
    BAZ = 1

    @classmethod
    def has_value(cls, val: int) -> bool:
        """Get if a value is in this enum.

        SEE: https://stackoverflow.com/a/43634746/11163122

        """
        return val in cls._value2member_map_  # Location of the false positive

Current behavior

Running pylint has the output:

has_value_enum.py:19:22: E1101: Class 'Foo' has no '_value2member_map_' member (no-member)

Expected behavior

As the _value2member_map_ attribute is present, I think pylint should not warn that it's not present.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.6 (default, Oct 27 2020, 11:18:42)
[Clang 12.0.0 (clang-1200.0.32.27)]
@hippo91
Copy link
Contributor

hippo91 commented Nov 19, 2020

@jamesbraza thanks for the report. It is probably a lack in the astroid's brain_namedtuple_enum brain.

@hippo91 hippo91 added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Nov 19, 2020
@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jun 30, 2022
mbyrnepr2 added a commit to mbyrnepr2/astroid that referenced this issue Oct 7, 2022
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Oct 7, 2022
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Oct 8, 2022
@mbyrnepr2 mbyrnepr2 added Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Oct 8, 2022
@mbyrnepr2
Copy link
Member

Can be closed once https://github.com/PyCQA/astroid/milestone/58 is released.

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.15.4, 2.15.5 Oct 8, 2022
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Oct 10, 2022
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Oct 10, 2022
@mbyrnepr2
Copy link
Member

Can be closed once https://github.com/PyCQA/astroid/milestone/58 is released.

Closing!

@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.15.5, 2.15.4 Oct 11, 2022
@cdce8p cdce8p modified the milestones: 2.15.4, 2.15.6 Nov 4, 2022
@cdce8p
Copy link
Member

cdce8p commented Nov 4, 2022

Unfortunately, this wasn't actually included in astroid 2.12.11. I've pinned it for 2.12.13 now.

@cdce8p cdce8p reopened this Nov 4, 2022
@mbyrnepr2 mbyrnepr2 self-assigned this Nov 5, 2022
@Pierre-Sassoulas Pierre-Sassoulas removed this from the 2.15.6 milestone Nov 14, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.7 milestone Nov 14, 2022
@jacobtylerwalls
Copy link
Member

Unfortunately, this wasn't actually included in astroid 2.12.11.

@cdce8p can you help me understand what you're referring to? When I compare the tags for 2.11 and 2.10, I see this change included. I also downloaded the source for 2.11 from PyPI to be absolutely sure, and I see it there also.

We might need to undo part of pylint-dev/astroid#1863.

@cdce8p
Copy link
Member

cdce8p commented Nov 19, 2022

Unfortunately, this wasn't actually included in astroid 2.12.11.

@cdce8p can you help me understand what you're referring to? When I compare the tags for 2.11 and 2.10, I see this change included. I also downloaded the source for 2.11 from PyPI to be absolutely sure, and I see it there also.

You're right. Seems like I got confused with the different commits. Usually I open the commit from them merge message (in the PR). I.e. this one: pylint-dev/astroid@3d4dc50. Looking at the branches / tags it's included only shows main. However that's only because the backport is a different commit.

We might need to undo part of PyCQA/astroid#1863.

Only partially, but yes. Would you like to do it?

@jacobtylerwalls
Copy link
Member

Sure thing! pylint-dev/astroid#1874

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 Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

No branches or pull requests

6 participants