-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
ilevkivskyi
merged 8 commits into
python:master
from
Michael0x2a:refine-enum-branch-analysis
Jul 8, 2019
Merged
Generalize reachability checks to support enums #7000
ilevkivskyi
merged 8 commits into
python:master
from
Michael0x2a:refine-enum-branch-analysis
Jul 8, 2019
Commits on Jun 16, 2019
-
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
Configuration menu - View commit details
-
Copy full SHA for df76db6 - Browse repository at this point
Copy the full SHA df76db6View commit details -
Configuration menu - View commit details
-
Copy full SHA for eaa0872 - Browse repository at this point
Copy the full SHA eaa0872View commit details
Commits on Jun 17, 2019
-
Co-Authored-By: Ran Benita <ran234@gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 4cb5572 - Browse repository at this point
Copy the full SHA 4cb5572View commit details
Commits on Jun 24, 2019
-
Configuration menu - View commit details
-
Copy full SHA for 0c084dc - Browse repository at this point
Copy the full SHA 0c084dcView commit details
Commits on Jul 6, 2019
-
Configuration menu - View commit details
-
Copy full SHA for 5ec6868 - Browse repository at this point
Copy the full SHA 5ec6868View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1d95ec0 - Browse repository at this point
Copy the full SHA 1d95ec0View commit details
Commits on Jul 8, 2019
-
Configuration menu - View commit details
-
Copy full SHA for d1d99a7 - Browse repository at this point
Copy the full SHA d1d99a7View commit details -
Merge branch 'refine-enum-branch-analysis' of github.com:Michael0x2a/…
…mypy into refine-enum-branch-analysis
Configuration menu - View commit details
-
Copy full SHA for 5b70ff5 - Browse repository at this point
Copy the full SHA 5b70ff5View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.