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

Fix False positive on Enum.__members__.items() #4135

Merged
merged 11 commits into from
Feb 27, 2021
11 changes: 11 additions & 0 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,17 @@ def _emit_no_member(node, owner, owner_name, ignored_mixins=True, ignored_none=T
return False
except astroid.NotFoundError:
return True
if (
owner.parent
and isinstance(owner.parent, astroid.ClassDef)
and owner.parent.name == "EnumMeta"
and owner_name == "__members__"
and node.attrname == "items"
):
# Avoid false positive on Enum.__members__.items()
# See https://github.com/PyCQA/pylint/issues/4123
return False

return True


Expand Down
10 changes: 10 additions & 0 deletions tests/functional/m/member_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,13 @@ def __init__(self, flag):
else:
self.attribute = []
self.attribute.append(1)

from enum import Enum
class Animal(Enum):
ANT = 1
BEE = 2
CAT = 3
DOG = 4
# To test false positive no-member on Enum.__members__.items()
for itm in Animal.__members__.items():
print(itm)