Skip to content

Commit

Permalink
Exclude the _ignore_ attribute from the __members__ container.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbyrnepr2 committed Sep 7, 2023
1 parent 600229f commit cdb452c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ Release date: TBA

Closes pylint-dev/pylint#8802


* Exclude the ``_ignore_`` attribute from the ``__members__`` container.

Closes pylint-dev/pylint#9015

* Fix inference of functions with ``@functools.lru_cache`` decorators without
parentheses.

Expand Down
5 changes: 4 additions & 1 deletion astroid/brain/brain_namedtuple_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ def infer_enum_class(node: nodes.ClassDef) -> nodes.ClassDef:
dunder_members = {}
target_names = set()
for local, values in node.locals.items():
if any(not isinstance(value, nodes.AssignName) for value in values):
if (
any(not isinstance(value, nodes.AssignName) for value in values)
or local == "_ignore_"
):
continue

stmt = values[0].statement()
Expand Down
22 changes: 22 additions & 0 deletions tests/brain/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,25 @@ def __init__(self, mass, radius):
mars, radius = enum_members.items
assert mars[1].name == "MARS"
assert radius[1].name == "radius"

def test_enum_with_ignore(self) -> None:
"""Exclude ``_ignore_`` from the ``__members__`` container
Originally reported in https://github.com/pylint-dev/pylint/issues/9015
"""

ast_node: nodes.Attribute = builder.extract_node(
"""
import enum
class MyEnum(enum.Enum):
FOO = enum.auto()
BAR = enum.auto()
_ignore_ = ["BAZ"]
BAZ = 42
MyEnum.__members__
"""
)
inferred = next(ast_node.infer())
members_names = [const_node.value for const_node, name_obj in inferred.items]
assert members_names == ["FOO", "BAR", "BAZ"]

0 comments on commit cdb452c

Please sign in to comment.