Closed
Description
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