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 'unsubscriptable-object' reported for Enum.__members__ attribute #4358

Closed
benburk opened this issue Apr 15, 2021 · 1 comment · Fixed by #4473
Closed

False positive 'unsubscriptable-object' reported for Enum.__members__ attribute #4358

benburk opened this issue Apr 15, 2021 · 1 comment · Fixed by #4473
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)

Comments

@benburk
Copy link

benburk commented Apr 15, 2021

Steps to reproduce

from enum import Enum
class Foo(Enum):
    BAR = 1
Foo.__members__['BAR']  # <-- error: Value 'Foo.__members__' is unsubscriptable

Current behavior

Final line alerts "Value 'Foo.__members__' is unsubscriptable"

Expected behavior

No error

pylint --version output

Result of pylint --version output:

pylint 2.7.4
astroid 2.5
Python 3.9.2 (default, Mar  3 2021, 11:58:52) 
[Clang 10.0.0 ]
@benburk benburk changed the title Incorrect 'unsubscriptable-object' reported for Enum.__members__ attribute False positive 'unsubscriptable-object' reported for Enum.__members__ attribute May 8, 2021
@hippo91
Copy link
Contributor

hippo91 commented May 13, 2021

@benburk thanks for the report. It seems that @nelfin is working on a fix through pylint-dev/astroid#941.

@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 May 13, 2021
nelfin added a commit to nelfin/astroid that referenced this issue May 13, 2021
Ref pylint-dev/pylint#2626. Ref pylint-dev/pylint#3535. Ref pylint-dev/pylint#4358.
This updates the namedtuple/enum brain to add a dictionary for
__members__
nelfin added a commit to nelfin/astroid that referenced this issue May 13, 2021
Ref pylint-dev/pylint#2626. Ref pylint-dev/pylint#3535. Ref pylint-dev/pylint#4358.
This updates the namedtuple/enum brain to add a dictionary for
__members__
nelfin added a commit to nelfin/astroid that referenced this issue May 14, 2021
Ref pylint-dev/pylint#3535. Ref pylint-dev/pylint#4358. This updates the
namedtuple/enum brain to add a dictionary for __members__
cdce8p pushed a commit to pylint-dev/astroid that referenced this issue May 15, 2021
#941)

* Add tests of failing property inference

Ref #940

* Fix inference of properties in a class context

Ref #940. If we are accessing an attribute and it is found on
type(A).__dict__ *and* it is a data descriptor, then we resolve that
descriptor. For the case of inferring a property which is accessed as a
class attribute, this equates to the property being defined on the
metaclass (which may be anywhere in the class hierarchy).

* Fix inference of Enum.__members__ property for subclasses

Ref pylint-dev/pylint#3535. Ref pylint-dev/pylint#4358. This updates the
namedtuple/enum brain to add a dictionary for __members__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants