File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ Release date: TBA
36
36
* On Python versions >= 3.9, ``astroid`` now understands subscripting
37
37
builtin classes such as ``enumerate`` or ``staticmethod``.
38
38
39
+ * Fixed inference of ``Enums`` when they are imported under an alias.
40
+
41
+ Closes PyCQA/pylint#5776
42
+
39
43
* Rename ``ModuleSpec`` -> ``module_type`` constructor parameter to match attribute
40
44
name and improve typing. Use ``type`` instead.
41
45
Original file line number Diff line number Diff line change @@ -349,11 +349,9 @@ def __mul__(self, other):
349
349
"""
350
350
351
351
352
- def infer_enum_class (node ) :
352
+ def infer_enum_class (node : nodes . ClassDef ) -> nodes . ClassDef :
353
353
"""Specific inference for enums."""
354
354
for basename in (b for cls in node .mro () for b in cls .basenames ):
355
- if basename not in ENUM_BASE_NAMES :
356
- continue
357
355
if node .root ().name == "enum" :
358
356
# Skip if the class is directly from enum module.
359
357
break
Original file line number Diff line number Diff line change @@ -1156,6 +1156,20 @@ class Animal(Enum):
1156
1156
self .assertIsInstance (inferred , astroid .Dict )
1157
1157
self .assertTrue (inferred .locals )
1158
1158
1159
+ def test_enum_as_renamed_import (self ) -> None :
1160
+ """Originally reported in https://github.com/PyCQA/pylint/issues/5776."""
1161
+ ast_node : nodes .Attribute = builder .extract_node (
1162
+ """
1163
+ from enum import Enum as PyEnum
1164
+ class MyEnum(PyEnum):
1165
+ ENUM_KEY = "enum_value"
1166
+ MyEnum.ENUM_KEY
1167
+ """
1168
+ )
1169
+ inferred = next (ast_node .infer ())
1170
+ assert isinstance (inferred , bases .Instance )
1171
+ assert inferred ._proxied .name == "ENUM_KEY"
1172
+
1159
1173
1160
1174
@unittest .skipUnless (HAS_DATEUTIL , "This test requires the dateutil library." )
1161
1175
class DateutilBrainTest (unittest .TestCase ):
You can’t perform that action at this time.
0 commit comments