Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3918,6 +3918,10 @@ def visit_assert_type_expr(self, expr: AssertTypeExpr) -> Type:
always_allow_any=True,
)
target_type = expr.type
if isinstance(mypy.types.get_proper_type(source_type), mypy.types.Instance) and (
hasattr(source_type, "last_known_value") and source_type.last_known_value is not None
):
source_type = source_type.last_known_value
Comment thread
CarlFK marked this conversation as resolved.
Outdated
if not is_same_type(source_type, target_type):
if not self.chk.in_checked_function():
self.msg.note(
Expand Down
2 changes: 2 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ reveal_type(returned) # N: Revealed type is "builtins.int"
assert_type(a, str) # E: Expression is of type "int", not "str"
assert_type(a, Any) # E: Expression is of type "int", not "Any"
assert_type(a, Literal[1]) # E: Expression is of type "int", not "Literal[1]"
assert_type(42, Literal[42])
assert_type(42, int) # E: Expression is of type "Literal[42]", not "int"
[builtins fixtures/tuple.pyi]

[case testAssertTypeGeneric]
Expand Down