Skip to content

Commit fe6412d

Browse files
committed
[mypyc] feat: support constant folding in ExpressionChecker.visit_typeddict_index_expr
1 parent 053c054 commit fe6412d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mypy/checkexpr.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from mypy.checker_shared import ExpressionCheckerSharedApi
1919
from mypy.checkmember import analyze_member_access, has_operator
2020
from mypy.checkstrformat import StringFormatterChecker
21+
from mypy.constant_fold import constant_fold_expr
2122
from mypy.erasetype import erase_type, remove_instance_last_known_values, replace_meta_vars
2223
from mypy.errors import ErrorInfo, ErrorWatcher, report_internal_error
2324
from mypy.expandtype import (
@@ -4620,8 +4621,8 @@ def union_tuple_fallback_item(self, left_type: TupleType) -> Type:
46204621
def visit_typeddict_index_expr(
46214622
self, td_type: TypedDictType, index: Expression, setitem: bool = False
46224623
) -> tuple[Type, set[str]]:
4623-
if isinstance(index, StrExpr):
4624-
key_names = [index.value]
4624+
if isinstance(folded_index := constant_fold_expr(index, "unused"), str):
4625+
key_names = [folded_index]
46254626
else:
46264627
typ = get_proper_type(self.accept(index))
46274628
if isinstance(typ, UnionType):

0 commit comments

Comments
 (0)