File tree 2 files changed +34
-1
lines changed 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,8 @@ def erase_type(typ: Type) -> Type:
27
27
class EraseTypeVisitor (TypeVisitor [Type ]):
28
28
29
29
def visit_unbound_type (self , t : UnboundType ) -> Type :
30
- assert False , 'Not supported'
30
+ # TODO: replace with an assert after UnboundType can't leak from semantic analysis.
31
+ return AnyType (TypeOfAny .from_error )
31
32
32
33
def visit_any (self , t : AnyType ) -> Type :
33
34
return t
Original file line number Diff line number Diff line change @@ -332,3 +332,35 @@ import c
332
332
import e
333
333
[file e.py]
334
334
1+'no' # E: Unsupported operand types for + ("int" and "str")
335
+
336
+ [case testModuleAsTypeNoCrash]
337
+ import mock
338
+ from typing import Union
339
+
340
+ class A: ...
341
+ class B: ...
342
+
343
+ x: Union[mock, A] # E: Invalid type "mock"
344
+
345
+ if isinstance(x, B):
346
+ pass
347
+ [file mock.py]
348
+ [builtins fixtures/isinstance.pyi]
349
+ [out]
350
+
351
+ [case testModuleAsTypeNoCrash2]
352
+ import mock
353
+ from typing import overload, Any, Union
354
+
355
+ @overload
356
+ def f(x: int) -> int: ...
357
+ @overload
358
+ def f(x: str) -> Union[mock, str]: ... # E: Invalid type "mock"
359
+ def f(x):
360
+ pass
361
+
362
+ x: Any
363
+ f(x)
364
+ [file mock.py]
365
+ [builtins fixtures/isinstance.pyi]
366
+ [out]
You can’t perform that action at this time.
0 commit comments