Skip to content

Commit

Permalink
Fix a crash when an enum class which is also decorated with a ``datac…
Browse files Browse the repository at this point in the history
…lasses.dataclass`` decorator is defined.

Closes #9100
  • Loading branch information
mbyrnepr2 committed Oct 3, 2023
1 parent f74200d commit df63e42
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9100.other
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash when an enum class which is also decorated with a ``dataclasses.dataclass`` decorator is defined.

Closes #9100
5 changes: 4 additions & 1 deletion pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2281,5 +2281,8 @@ def is_enum_member(node: nodes.AssignName) -> bool:
):
return False

enum_member_objects = frame.locals.get("__members__")[0].items
try:
enum_member_objects = frame.locals.get("__members__")[0].items
except TypeError:
return False
return node.name in [name_obj.name for value, name_obj in enum_member_objects]
8 changes: 7 additions & 1 deletion tests/functional/i/invalid/invalid_name/invalid_name_enum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
""" Tests for invalid-name checker in the context of enums. """
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods, missing-class-docstring


from dataclasses import dataclass
from enum import Enum


Expand All @@ -28,3 +29,8 @@ def __init__(self, red: int, green: int, blue: int) -> None:
def as_hex(self) -> str:
"""Get hex 'abcdef' representation for a color."""
return f'{self.red:0{2}x}{self.green:0{2}x}{self.blue:0{2}x}'


@dataclass
class Something(str, Enum):
asd: str = 'sdf'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invalid-name:16:4:16:14:Color:"Class constant name ""aquamarine"" doesn't conform to UPPER_CASE naming style":HIGH
invalid-name:17:4:17:14:Color:"Class constant name ""aquamarine"" doesn't conform to UPPER_CASE naming style":HIGH

0 comments on commit df63e42

Please sign in to comment.