Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3710,6 +3710,10 @@ def try_infer_partial_generic_type_from_assignment(
return
rvalue_type = self.expr_checker.accept(rvalue)
rvalue_type = get_proper_type(rvalue_type)
if var not in partial_types:
# Evaluating rvalue may have already resolved this partial type
# (e.g. a walrus assignment to the same variable inside rvalue).
return
if isinstance(rvalue_type, Instance):
if rvalue_type.type == typ.type and is_valid_inferred_type(
rvalue_type, self.options
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-python38.test
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,15 @@ def check_partial_list() -> None:
reveal_type(z) # N: Revealed type is "builtins.list[builtins.int]"
[builtins fixtures/list.pyi]

[case testWalrusPartialTypeShadowedInComprehension]
# https://github.com/python/mypy/issues/20792
errors = []
errors = [
i for i in [1, 2, 3] if (errors := [1])
]
reveal_type(errors) # N: Revealed type is "builtins.list[builtins.int]"
[builtins fixtures/list.pyi]

[case testWalrusAssignmentAndConditionScopeForLiteral]
# flags: --warn-unreachable

Expand Down
Loading