Skip to content

Commit

Permalink
Fix assert_type failures when some nodes are deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Aug 21, 2023
1 parent 2c1fd97 commit 944acf5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mypy/checkexpr.py
Expand Up @@ -4271,6 +4271,9 @@ def visit_assert_type_expr(self, expr: AssertTypeExpr) -> Type:
allow_none_return=True,
always_allow_any=True,
)
if self.chk.current_node_deferred:
return source_type

target_type = expr.type
proper_source_type = get_proper_type(source_type)
if (
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-expressions.test
Expand Up @@ -1045,6 +1045,23 @@ def reduce_it(s: Scalar) -> Scalar:
assert_type(reduce_it(True), Scalar)
[builtins fixtures/tuple.pyi]

[case testAssertTypeWithDeferedNodes]
from typing import Callable, TypeVar, assert_type

T = TypeVar("T")

def dec(f: Callable[[], T]) -> Callable[[], T]:
return f

def method1() -> None:
some_enum = _inner_method1()
assert_type(some_enum, int)

@dec
def _inner_method1() -> int:
return 1
[builtins fixtures/tuple.pyi]

-- None return type
-- ----------------

Expand Down

0 comments on commit 944acf5

Please sign in to comment.