Skip to content
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

Fix assert_type failures when some nodes are deferred #15920

Merged
merged 2 commits into from Aug 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 testAssertTypeWithDeferredNodes]
from typing import Callable, TypeVar, assert_type

T = TypeVar("T")

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

def func() -> None:
some = _inner_func()
assert_type(some, int)

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

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

Expand Down