Skip to content

Change of binder behavior whan narrowing to unrelated type #18967

Closed
@JukkaL

Description

@JukkaL

The behavior in this example was changed in #18538:

def any():
    return 1

def f() -> None:
    x = "a"
    x = any()
    assert isinstance(x, int)
    reveal_type(x)  # "Never", but used to be unreachable (no message)

In the past, the code after isinstance was silently unchecked. Now the inferred type is Never, which will likely generate false positives. Neither behavior is great, but users may consider the switch from false negatives to false positives to be a regression. I'm not sure what we should do here. If we'd allow variables to be redefined freely, there would be no issue.

cc @ilevkivskyi who authored the PR that changed the behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions