Skip to content

Commit d829376

Browse files
author
Guido van Rossum
committed
Respond to review by @ilevkivskyi
1 parent 5543b5a commit d829376

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ def visit_index_expr_helper(self, e: IndexExpr) -> Type:
14401440
elif isinstance(left_type, TypedDictType):
14411441
return self.visit_typeddict_index_expr(left_type, e.index)
14421442
elif (isinstance(left_type, CallableType)
1443-
and left_type.is_type_obj() and left_type.type_object()):
1443+
and left_type.is_type_obj() and left_type.type_object().is_enum):
14441444
return self.visit_enum_index_expr(left_type.type_object(), e.index, e)
14451445
else:
14461446
result, method_type = self.check_op('__getitem__', left_type, e.index, e)

test-data/unit/pythoneval-enum.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,11 @@ s = None # type: str
149149
reveal_type(E[s])
150150
[out]
151151
_program.py:5: error: Revealed type is '_testEnumIndex.E'
152+
153+
[case testEnumIndexError]
154+
from enum import IntEnum
155+
class E(IntEnum):
156+
a = 1
157+
E[1]
158+
[out]
159+
_program.py:4: error: Enum index should be a string (actual index type "int")

0 commit comments

Comments
 (0)