Skip to content

PEP 572: Assignments not narrowed in right-hand side of and #7313

Closed
@JelleZijlstra

Description

@JelleZijlstra

The binder interaction doesn't work properly for assignments in the right-hand side of an and (after if x and (y := 1):, the type of y isn't narrowed to int).

Test case:


[case testAndRHS]
from typing import Optional

def f(x: Optional[int], y: Optional[int]) -> None:
    if x and (y := 1):
        reveal_type(y)  # N: Revealed type is 'builtins.int'

(Currently it produces Revealed type is 'Union[builtins.int, None]' instead.)

Followup from #6899

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions