File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4264,6 +4264,28 @@ def check_or_nested(maybe: bool) -> None:
42644264 reveal_type(bar) # N: Revealed type is "builtins.list[builtins.int]"
42654265 reveal_type(baz) # N: Revealed type is "builtins.list[builtins.int]"
42664266
4267+ [case testInferWalrusAssignmentNestedInAndExpr]
4268+ # Walrus narrowing should propagate when the assignment is nested inside
4269+ # an arbitrary expression on the right side of an "and" condition.
4270+ # Regression test for https://github.com/python/mypy/issues/19430
4271+ class Node:
4272+ def __init__(self, value: bool) -> None:
4273+ self.value = value
4274+
4275+ def check_walrus_in_unary(cond: bool) -> None:
4276+ woo = None
4277+ if cond and not (woo := Node(True)).value:
4278+ reveal_type(woo) # N: Revealed type is "__main__.Node"
4279+ else:
4280+ reveal_type(woo) # N: Revealed type is "__main__.Node | None"
4281+
4282+ def check_walrus_in_nested_call(cond: bool) -> None:
4283+ woo = None
4284+ if cond and (woo := Node(True)).value:
4285+ reveal_type(woo) # N: Revealed type is "__main__.Node"
4286+ else:
4287+ reveal_type(woo) # N: Revealed type is "__main__.Node | None"
4288+
42674289[case testInferOptionalAgainstAny]
42684290from typing import Any, Optional, TypeVar
42694291
You can’t perform that action at this time.
0 commit comments