Skip to content

Strict optional doesn't recognize "None in (...)" tests #2980

Description

@JukkaL

A user reported code which basically boils down to this:

class A:
    a: Optional[int]
    b: Optional[int]
    ...
    def f(self) -> None:
        if None in (self.a, self.b):
            return
        print(self.a + self.b)  # ok at runtime but mypy error currently

Mypy doesn't recognize the None in (...) test as a legitimate None test.

The code seems a little unusual but if we see this frequently enough it might be worth supporting at some point.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions