Skip to content

Commit 95a04d9

Browse files
committed
Fix self check
1 parent 9588703 commit 95a04d9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

mypy/exportjson.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
import argparse
1717
import json
18-
from typing import Any, TypeAlias as _TypeAlias
18+
from typing import Any, Union
19+
from typing_extensions import TypeAlias as _TypeAlias
1920

2021
from librt.internal import Buffer
2122

@@ -67,7 +68,7 @@
6768
get_proper_type,
6869
)
6970

70-
Json: _TypeAlias = dict[str, Any] | str
71+
Json: _TypeAlias = Union[dict[str, Any], str]
7172

7273

7374
class Config:
@@ -93,7 +94,7 @@ def convert_mypy_file_to_json(self: MypyFile, cfg: Config) -> Json:
9394

9495

9596
def 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

117118
def 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

216217
def 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:
368369
def 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

Comments
 (0)