Skip to content

Commit

Permalink
Remove an assert triggered by UnboundType leaking from semanal.py (#5258
Browse files Browse the repository at this point in the history
)

Fixes #4543

This is also a temporary solution for #4987. A permanent one would be to turn UnboundTypes into Anys directly in semanal.py.
  • Loading branch information
ilevkivskyi authored Jun 21, 2018
1 parent bd9e93b commit aa82bd5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def erase_type(typ: Type) -> Type:
class EraseTypeVisitor(TypeVisitor[Type]):

def visit_unbound_type(self, t: UnboundType) -> Type:
assert False, 'Not supported'
# TODO: replace with an assert after UnboundType can't leak from semantic analysis.
return AnyType(TypeOfAny.from_error)

def visit_any(self, t: AnyType) -> Type:
return t
Expand Down
32 changes: 32 additions & 0 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,35 @@ import c
import e
[file e.py]
1+'no' # E: Unsupported operand types for + ("int" and "str")

[case testModuleAsTypeNoCrash]
import mock
from typing import Union

class A: ...
class B: ...

x: Union[mock, A] # E: Invalid type "mock"

if isinstance(x, B):
pass
[file mock.py]
[builtins fixtures/isinstance.pyi]
[out]

[case testModuleAsTypeNoCrash2]
import mock
from typing import overload, Any, Union

@overload
def f(x: int) -> int: ...
@overload
def f(x: str) -> Union[mock, str]: ... # E: Invalid type "mock"
def f(x):
pass

x: Any
f(x)
[file mock.py]
[builtins fixtures/isinstance.pyi]
[out]

0 comments on commit aa82bd5

Please sign in to comment.