Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 2 additions & 4 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,11 +1656,9 @@ def redundant_cast(self, typ: Type, context: Context) -> None:
)

def assert_type_fail(self, source_type: Type, target_type: Type, context: Context) -> None:
(source, target) = format_type_distinctly(source_type, target_type, options=self.options)
self.fail(
f"Expression is of type {format_type(source_type, self.options)}, "
f"not {format_type(target_type, self.options)}",
context,
code=codes.ASSERT_TYPE,
f"Expression is of type {source}, not {target}", context, code=codes.ASSERT_TYPE
)

def unimported_type_becomes_any(self, prefix: str, typ: Type, ctx: Context) -> None:
Expand Down
28 changes: 28 additions & 0 deletions test-data/unit/check-assert-type-fail.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[case testAssertTypeFail1]
import typing
import array as arr
class array:
pass
def f(si: arr.array[int]):
typing.assert_type(si, array) # E: Expression is of type "array.array[int]", not "__main__.array"
[builtins fixtures/tuple.pyi]

[case testAssertTypeFail2]
import typing
import array as arr
class array:
class array:
i = 1
def f(si: arr.array[int]):
typing.assert_type(si, array.array) # E: Expression is of type "array.array[int]", not "__main__.array.array"
[builtins fixtures/tuple.pyi]

[case testAssertTypeFail3]
import typing
import array as arr
class array:
class array:
i = 1
def f(si: arr.array[int]):
typing.assert_type(si, int) # E: Expression is of type "array[int]", not "int"
[builtins fixtures/tuple.pyi]