Skip to content

Remove an assert triggered by UnboundType leaking from semanal.py #5258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]