KEMBAR78
`--strict-optional` warns in boolean expression `x is not None and x > 10` · Issue #3643 · python/mypy · GitHub
Skip to content

--strict-optional warns in boolean expression x is not None and x > 10 #3643

@rowillia

Description

@rowillia
x = None  # In the real world x is in an untyped module and sometimes gets set

def method() -> None:
    if x is not None and x > 10:  # Unsupported operand types for < ("int" and None)
        pass
$ mypy --strict-optional test_none_branch.py
test_none_branch.py:4: error: Unsupported operand types for < ("int" and None)

I'm guessing the correct behavior of binder.py should assume the type is Any if previous statements in a boolean expression invalidate the only possible types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions