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 missing docstring on enum name property #2648

Merged
merged 3 commits into from
Dec 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions astroid/brain/brain_namedtuple_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,16 @@ def _name_(self):
# know that it should be a string, so infer that as a guess.
if "name" not in target_names:
code = dedent(
"""
@property
def name(self):
return ''
"""
'''
@property
def name(self):
"""The name of the Enum member.

This is a reconstruction by astroid: enums are too dynamic to understand, but we at least
know 'name' should be a string, so this is astroid's best guess.
"""
return ''
'''
)
name_dynamicclassattr = AstroidBuilder(AstroidManager()).string_build(code)[
"name"
Expand Down
12 changes: 12 additions & 0 deletions tests/brain/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ def func(self):
next(i_value.infer())
next(c_value.infer())

def test_enum_name_property_has_docstring(self) -> None:
code = """
from enum import Enum
class EmptyEnum(Enum): #@
...
"""
node = astroid.extract_node(code)
name_property = next(node.mymethods())

assert name_property.name == "name"
assert name_property.doc_node is not None

def test_enum_name_and_value_members_override_dynamicclassattr(self) -> None:
code = """
from enum import Enum
Expand Down
Loading