Skip to content

Make type refinement to work with None in [a, b, c] #17152

Open

Description

@eladshoshani

Following the bug report, when checking if multiple variables are not None using the syntax None in <some_collection> mypy should be able to refine the types of these variables to non-Optional types after this check.

Activity

  1. bhperry commented on May 20, 2024

    @bhperry

    Similarly, mypy does not do type narrowing for cases like:

    somevar: MyEnum
    if somevar in (MyEnum.A, MyEnum.C):
      myfunction(somevar)
    

    If myfunction is typed with Literal[MyEnum.A, MyEnum.C], then mypy complains

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions