-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 subclass of enum.Enum
#533
Comments
Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore): Yes, this was intentional (handling subclasses for enums was a little complicated when support for them was added). This should be fixed in astroid at some point, here's the relevant code: https://bitbucket.org/logilab/astroid/src/f75482328c8c39538c74fa9a85915ec5c58ce1fa/astroid/brain/py2stdlib.py?at=default#cl-281 |
have the same problem.
|
Is there anything that can be done in this issue? |
@LJBD Apart of disabling the check for now, no, there's no other solution. It would be great to have this fixed, but can't promise exactly when that's going to happen, unless someone proposes a patch to speed this up. |
FYI a partial workaround here is to define your enum overrides as a mixin, and then subclass enum explicitly in all of your "subclasses." For example: from enum import Enum
class SpecialEnumMixin:
def __new__(cls, value, info):
obj = object.__new__(cls)
obj._value_ = value
obj._info = info
return obj
@property
def info(self):
return self._info
class SpecialEnum(SpecialEnumMixin, Enum):
A = ("a", "this is a")
B = ("b", "this is b")
assert SpecialEnum.A.info == "this is a"
assert SpecialEnum("a") is SpecialEnum.A Doing it this way, pylint recognizes the "subclass" correctly as an enum. |
Is there a way to disable such |
Why people didn't fix this? |
@gbrennon looks like they're willing to accept patches if you can find the cause of the issue and fix it yourself |
@dufferzafar : this might help https://pylint.readthedocs.io/en/latest/user_guide/message-control.html |
In pylint 2.8 the result is now:
So it's still an issue. The relevant code seems to be here: https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_namedtuple_enum.py |
no-member
for subclass of enum.Enum
I still get the false positive E1101 for self defined members. Example:
pylint --versionpylint 2.11.1 Should I create a new issue for it? |
That syntax is very handy, I did not know it worked. Could you open a new issue, please ? |
❤ #5138 created |
Hi @Pierre-Sassoulas, I see the same behaviour when I'm importing enum.Enum with a different name (to prevent confusion when also doing
The error goes away when
Should I open a new issue or this one can be reopened? |
Thank you for the report, could you open a new issue, please ? :) |
Opened #5776, thanks! :) |
Originally reported by: BitBucket: iceout, GitHub: @iceout?
Python-2.7.6 + enum34 (Enum backported from Python-3.4.0)
test code:
pylint -E test.py
:The text was updated successfully, but these errors were encountered: