Skip to content

[1.15 regression] (Temporary) false positive for reachability with unannotated partial type #18606

Closed

Description

@hauntsaninja

Sort of a weird / minor case, but with mypy 1.15

λ cat e.py
def merge_debugs(debugs: list[int | None]) -> None:
    metadata = None
    for debug in debugs:
        if debug is not None:
            if metadata is None:
                metadata = {}

λ mypy  e.py --warn-unreachable
e.py:6: error: Need type annotation for "metadata" (hint: "metadata: dict[<type>, <type>] = ...")  [var-annotated]
e.py:6: error: Statement is unreachable  [unreachable]
Found 2 errors in 1 file (checked 1 source file)

If you add an annotation to metadata (standalone or with the assignment) the unreachable warning goes away

Activity

  1. changed the title [-]False positive for reachability with unannotated partial type[/-] [+](Temporary) false positive for reachability with unannotated partial type[/+] on Feb 5, 2025
  2. self-assigned this
    on Feb 5, 2025
  3. Garrett-R commented on Feb 9, 2025

    @Garrett-R

    Another example:

    y = None
    for i in range(5):
        if y is None:
            print('reachable!')  # Mypy: error: Statement is unreachable
            y = []
        y.append(99)

    (playground)

  4. changed the title [-](Temporary) false positive for reachability with unannotated partial type[/-] [+][1.15 regression] (Temporary) false positive for reachability with unannotated partial type[/+] on Feb 12, 2025
  5. added a commit that references this issue on Jun 6, 2025
    55c4067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions