Skip to content

Commit fb9134d

Browse files
committed
Succeed even if there are unsupported node types, but report error in output JSON
Also add tests.
1 parent 222a9fb commit fb9134d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

mypy/exportjson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def convert_symbol_node(self: SymbolNode, cfg: Config) -> Json:
152152
return convert_param_spec_expr(self)
153153
elif isinstance(self, TypeVarTupleExpr):
154154
return convert_type_var_tuple_expr(self)
155-
assert False, type(self)
155+
return {"ERROR": f"{type(self)!r} unrecognized"}
156156

157157

158158
def convert_func_def(self: FuncDef) -> Json:
@@ -364,7 +364,7 @@ def convert_type(typ: Type) -> Json:
364364
return convert_typeddict_type(typ)
365365
elif isinstance(typ, UnboundType):
366366
return convert_unbound_type(typ)
367-
assert False, type(typ)
367+
return {"ERROR": f"{type(typ)!r} unrecognized"}
368368

369369

370370
def convert_instance(self: Instance) -> Json:

mypy/test/testexportjson.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
5959
if '"path": ' in line:
6060
# We source file path is unpredictable, so filter it out
6161
line = re.sub(r'"[^"]+\.pyi?"', "...", line)
62+
assert "ERROR" not in line, line
6263
a.append(line)
6364
except CompileError as e:
6465
a = e.messages

test-data/unit/exportjson.test

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def foo(a: int) -> None: ...
193193
[case testExportDifferentTypes]
194194
from __future__ import annotations
195195

196-
from typing import Callable, Any, Literal, NoReturn
196+
from typing import Callable, Any, Literal, NoReturn, TypedDict, NamedTuple
197197

198198
list_ann: list[int]
199199
any_ann: Any
@@ -209,7 +209,17 @@ def f() -> NoReturn:
209209
BadType = 1
210210
x: BadType # type: ignore
211211

212+
class TD(TypedDict):
213+
x: int
214+
215+
td = TD(x=1)
216+
217+
NT = NamedTuple("NT", [("x", int)])
218+
219+
nt = NT(x=1)
220+
212221
[builtins fixtures/tuple.pyi]
222+
[typing fixtures/typing-medium.pyi]
213223
[out]
214224
<not checked>
215225

0 commit comments

Comments
 (0)