Skip to content

Block incorrectly treated as unreachable when strict optional disabled #6827

@JukkaL

Description

@JukkaL

This program doesn't generate an error when using --no-strict-optional, even though every line is reachable:

from typing import NamedTuple, Dict

class C(NamedTuple):
    a: int
    b: str

x: Dict[int, C]
y = x.get(int())
if not y:
    1 + ''  # No error (considered unreachable)

Apparently mypy thinks that the tuple object is always truthy, even though it could also be None when strict optional checking is disabled.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions