Skip to content

Commit

Permalink
Add _value2member_map_ member to the enum brain. (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbyrnepr2 authored and Pierre-Sassoulas committed Oct 10, 2022
1 parent 9c3b002 commit eafc0ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -7,6 +7,10 @@ What's New in astroid 2.13.0?
Release date: TBA


* 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

0 comments on commit eafc0ff

Please sign in to comment.