1515
1616import argparse
1717import json
18- from typing import Any , TypeAlias as _TypeAlias
18+ from typing import Any , Union
19+ from typing_extensions import TypeAlias as _TypeAlias
1920
2021from librt .internal import Buffer
2122
6768 get_proper_type ,
6869)
6970
70- Json : _TypeAlias = dict [str , Any ] | str
71+ Json : _TypeAlias = Union [ dict [str , Any ], str ]
7172
7273
7374class Config :
@@ -93,7 +94,7 @@ def convert_mypy_file_to_json(self: MypyFile, cfg: Config) -> Json:
9394
9495
9596def convert_symbol_table (self : SymbolTable , cfg : Config ) -> Json :
96- data : Json = {".class" : "SymbolTable" }
97+ data : dict [ str , Any ] = {".class" : "SymbolTable" }
9798 for key , value in self .items ():
9899 # Skip __builtins__: it's a reference to the builtins
99100 # module that gets added to every module by
@@ -115,7 +116,7 @@ def convert_symbol_table(self: SymbolTable, cfg: Config) -> Json:
115116
116117
117118def convert_symbol_table_node (self : SymbolTableNode , cfg : Config ) -> Json :
118- data : Json = {".class" : "SymbolTableNode" , "kind" : node_kinds [self .kind ]}
119+ data : dict [ str , Any ] = {".class" : "SymbolTableNode" , "kind" : node_kinds [self .kind ]}
119120 if self .module_hidden :
120121 data ["module_hidden" ] = True
121122 if not self .module_public :
@@ -214,7 +215,7 @@ def convert_decorator(self: Decorator) -> Json:
214215
215216
216217def convert_var (self : Var ) -> Json :
217- data : Json = {
218+ data : dict [ str , Any ] = {
218219 ".class" : "Var" ,
219220 "name" : self ._name ,
220221 "fullname" : self ._fullname ,
@@ -368,9 +369,12 @@ def convert_type(typ: Type) -> Json:
368369def convert_instance (self : Instance ) -> Json :
369370 ready = self .type is not NOT_READY
370371 if not self .args and not self .last_known_value and not self .extra_attrs :
371- return self .type .fullname if ready else self .type_ref
372+ if ready :
373+ return self .type .fullname
374+ elif self .type_ref :
375+ return self .type_ref
372376
373- data : Json = {
377+ data : dict [ str , Any ] = {
374378 ".class" : "Instance" ,
375379 "type_ref" : self .type .fullname if ready else self .type_ref ,
376380 "args" : [convert_type (arg ) for arg in self .args ],
0 commit comments