1
1
"""Semantic analysis of TypedDict definitions."""
2
2
3
3
from collections import OrderedDict
4
- from typing import Optional , List , Set , Tuple , cast
4
+ from typing import Optional , List , Set , Tuple
5
5
from typing_extensions import Final
6
6
7
7
from mypy .types import Type , AnyType , TypeOfAny , TypedDictType , TPDICT_NAMES
@@ -191,12 +191,11 @@ def check_typeddict(self,
191
191
# This is a valid typed dict, but some type is not ready.
192
192
# The caller should defer this until next iteration.
193
193
return True , None
194
- items , types , total , ok = res
194
+ name , items , types , total , ok = res
195
195
if not ok :
196
196
# Error. Construct dummy return value.
197
197
info = self .build_typeddict_typeinfo ('TypedDict' , [], [], set ())
198
198
else :
199
- name = cast (StrExpr , call .args [0 ]).value
200
199
if var_name is not None and name != var_name :
201
200
self .fail (
202
201
"First argument '{}' to TypedDict() does not match variable name '{}'" .format (
@@ -216,7 +215,7 @@ def check_typeddict(self,
216
215
call .analyzed .set_line (call .line , call .column )
217
216
return True , info
218
217
219
- def parse_typeddict_args (self , call : CallExpr ) -> Optional [Tuple [List [str ], List [Type ],
218
+ def parse_typeddict_args (self , call : CallExpr ) -> Optional [Tuple [str , List [str ], List [Type ],
220
219
bool , bool ]]:
221
220
"""Parse typed dict call expression.
222
221
@@ -262,7 +261,7 @@ def parse_typeddict_args(self, call: CallExpr) -> Optional[Tuple[List[str], List
262
261
if has_any_from_unimported_type (t ):
263
262
self .msg .unimported_type_becomes_any ("Type of a TypedDict key" , t , dictexpr )
264
263
assert total is not None
265
- return items , types , total , ok
264
+ return args [ 0 ]. value , items , types , total , ok
266
265
267
266
def parse_typeddict_fields_with_types (
268
267
self ,
@@ -293,9 +292,9 @@ def parse_typeddict_fields_with_types(
293
292
return items , types , True
294
293
295
294
def fail_typeddict_arg (self , message : str ,
296
- context : Context ) -> Tuple [List [str ], List [Type ], bool , bool ]:
295
+ context : Context ) -> Tuple [str , List [str ], List [Type ], bool , bool ]:
297
296
self .fail (message , context )
298
- return [], [], True , False
297
+ return '' , [], [], True , False
299
298
300
299
def build_typeddict_typeinfo (self , name : str , items : List [str ],
301
300
types : List [Type ],
0 commit comments