Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize reachability checks to support enums #7000

Merged
merged 8 commits into from
Jul 8, 2019

Commits on Jun 16, 2019

  1. Generalize reachability checks to support enums

    This diff adds support for performing reachability and narrowing
    analysis when doing certain enum checks.
    
    For example, given the following enum:
    
        class Foo(Enum):
            A = 1
            B = 2
    
    ...this pull request will make mypy do the following:
    
        x: Foo
        if x is Foo.A:
            reveal_type(x)  # type: Literal[Foo.A]
        elif x is Foo.B:
            reveal_type(x)  # type: Literal[Foo.B]
        else:
            reveal_type(x)  # No output: branch inferred as unreachable
    
    This diff does not attempt to perform this same sort of narrowing for
    equality checks: I suspect implementing those will be harder due to
    their overridable nature. (E.g. you can define custom `__eq__` methods
    within Enum subclasses).
    
    This pull request also finally adds support for the enum behavior
    [described in PEP 484][0] and also sort of partially addresses
    python#6366
    
      [0]: https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions
    Michael0x2a committed Jun 16, 2019
    Configuration menu
    Copy the full SHA
    df76db6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    eaa0872 View commit details
    Browse the repository at this point in the history

Commits on Jun 17, 2019

  1. Add missing word to docstring

    Co-Authored-By: Ran Benita <ran234@gmail.com>
    Michael0x2a and bluetech authored Jun 17, 2019
    Configuration menu
    Copy the full SHA
    4cb5572 View commit details
    Browse the repository at this point in the history

Commits on Jun 24, 2019

  1. Configuration menu
    Copy the full SHA
    0c084dc View commit details
    Browse the repository at this point in the history

Commits on Jul 6, 2019

  1. Configuration menu
    Copy the full SHA
    5ec6868 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1d95ec0 View commit details
    Browse the repository at this point in the history

Commits on Jul 8, 2019

  1. Update comment

    Michael0x2a committed Jul 8, 2019
    Configuration menu
    Copy the full SHA
    d1d99a7 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'refine-enum-branch-analysis' of github.com:Michael0x2a/…

    …mypy into refine-enum-branch-analysis
    Michael0x2a committed Jul 8, 2019
    Configuration menu
    Copy the full SHA
    5b70ff5 View commit details
    Browse the repository at this point in the history