-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 with subclassed Enums #2626
Comments
Thanks for the report! |
I believe this problem happens regardless of subclassing. What will it take for pylint/astroid to be aware of Enum's patching of class members? |
Just adding more examples on this as it may help close this issue. import typing
from enum import Enum
class MyEnum(Enum):
def to_pb2(self) -> int:
return typing.cast(int, self.value)
def __str__(self) -> str:
return self.name.upper() # pylint: disable=no-member
class SomeEnum(MyEnum):
A = "A"
class AnotherEnum(Enum):
B = "B"
SomeEnum.__members__.items()
AnotherEnum.__members__.items() This will report an issue for |
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__
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 do you have a PR forthcoming? nelfin/astroid@afd0c2b It seems as astroid gets smarter about propagating inference, I hit this problem more and more in my codebase. |
@belm0, the fix you reference made it into the main astroid branch as pylint-dev/astroid@8181dc9 (see pylint-dev/astroid#941). It should be available in astroid 2.5.7 and later |
Will be available in pylint 2.9.0 (see milestone for release planning), or you can have it with pylint 2.8.2 if you set the astroid version to 2.5.8 yourself. |
@nelfin I'm actually still seeing this problem with subclassed enums on the latest astroid (2.5.8) and pylint pre-release. Has anyone confirmed otherwise? |
Ah, now I understand. The commits we've been talking about actually only address the issue in the comment by bhargavrpatel above (#2626 (comment)), which talks about |
If there's any guidance you can offer on what this problem might be or what parts of the implementation to poke at, I can try looking at it. |
@belm0, I think |
Adding custom methods to an Enum subclass and then implementing it: pylint can't see the new methods.
Similar to #1932 and #2062
The text was updated successfully, but these errors were encountered: