Skip to content

False positive with warn unreachable, Any, and None #20532

@hauntsaninja

Description

@hauntsaninja
from typing import Any

def main(contents: Any, commit: str | None) -> None:
    if (
        contents.get("commit") == commit
        and (commit is not None or print("can_be_reached"))
    ):
        pass

main({"commit": None}, None)

mypy 1.19.1 with --warn-unreachable gives main.py:6: error: Right operand of "or" is never evaluated [unreachable]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions