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

Add _value2member_map_ member to the enum brain. #1820

Merged
merged 1 commit into from Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -20,6 +20,10 @@ Release date: TBA

Refs PyCQA/pylint#2567

* Add ``_value2member_map_`` member to the ``enum`` brain.

Refs PyCQA/pylint#3941


What's New in astroid 2.12.11?
==============================
Expand Down
4 changes: 4 additions & 0 deletions astroid/brain/brain_namedtuple_enum.py
Expand Up @@ -425,6 +425,10 @@ def name(self):
new_targets.append(fake.instantiate_class())
dunder_members[local] = fake
node.locals[local] = new_targets

# The undocumented `_value2member_map_` member:
node.locals["_value2member_map_"] = [nodes.Dict(parent=node)]

members = nodes.Dict(parent=node)
members.postinit(
[
Expand Down
15 changes: 15 additions & 0 deletions tests/unittest_scoped_nodes.py
Expand Up @@ -2534,6 +2534,21 @@ class Veg(Enum):
assert inferred_member_value.value is None


def test_enums_value2member_map_() -> None:
"""Check the `_value2member_map_` member is present in an Enum class"""
node = builder.extract_node(
"""
from enum import Enum
class Veg(Enum):
TOMATO: 1

Veg
"""
)
inferred_class = node.inferred()[0]
assert "_value2member_map_" in inferred_class.locals


@pytest.mark.parametrize("annotation, value", [("int", 42), ("bytes", b"")])
def test_enums_type_annotation_non_str_member(annotation, value) -> None:
"""A type-annotated member of an Enum class where:
Expand Down