Skip to content

Commit e804e8d

Browse files
authored
Fix assert_type failures when some nodes are deferred (#15920)
Now it is quite the same as `reveal_type`. Which is defined here: https://github.com/python/mypy/blob/2c1fd97986064161c542956bb3d9d5043dc0a480/mypy/checkexpr.py#L4297 Closes #15851
1 parent 2c1fd97 commit e804e8d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mypy/checkexpr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4271,6 +4271,9 @@ def visit_assert_type_expr(self, expr: AssertTypeExpr) -> Type:
42714271
allow_none_return=True,
42724272
always_allow_any=True,
42734273
)
4274+
if self.chk.current_node_deferred:
4275+
return source_type
4276+
42744277
target_type = expr.type
42754278
proper_source_type = get_proper_type(source_type)
42764279
if (

test-data/unit/check-expressions.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,23 @@ def reduce_it(s: Scalar) -> Scalar:
10451045
assert_type(reduce_it(True), Scalar)
10461046
[builtins fixtures/tuple.pyi]
10471047

1048+
[case testAssertTypeWithDeferredNodes]
1049+
from typing import Callable, TypeVar, assert_type
1050+
1051+
T = TypeVar("T")
1052+
1053+
def dec(f: Callable[[], T]) -> Callable[[], T]:
1054+
return f
1055+
1056+
def func() -> None:
1057+
some = _inner_func()
1058+
assert_type(some, int)
1059+
1060+
@dec
1061+
def _inner_func() -> int:
1062+
return 1
1063+
[builtins fixtures/tuple.pyi]
1064+
10481065
-- None return type
10491066
-- ----------------
10501067

0 commit comments

Comments
 (0)