-
-
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
Add interactions between Literal and Final #6081
Add interactions between Literal and Final #6081
Commits on Jan 3, 2019
-
Add interactions between Literal and Final
This pull request adds logic to handle interactions between Literal and Final: for example, inferring that `foo` has type `Literal[3]` when doing `foo: Final = 3`. A few additional notes: 1. This unfortunately had the side-effect of causing some of the existing tests for `Final` become noiser. I decided to mostly bias towards preserving the original error messages by modifying many of the existing variable assignments to explicitly use things like `Final[int]`. I left in the new error messages in a few cases -- mostly in cases where I was able to add them in a relatively tidy way. Let me know if this needs to be handled differently. 2. Since mypy uses 'Final', this means that once this PR lands, mypy itself will actually be using Literal types (albeit somewhat indirectly) for the first time. I'm not fully sure what the ramifications of this are. For example, do we need to detour and add support for literal types to mypyc? 3. Are there any major users of `Final` other then mypy? It didn't seem like we were really using it in our internal codebase at least, but I could be wrong about that. If there *are* some people who have already started depending on 'Final', maybe we should defer landing this PR until Literal types are more stable to avoid disrupting them. I had to make a few changes to mypy's own source code to get it to type check under these new semantics, for example.
Configuration menu - View commit details
-
Copy full SHA for e5a7495 - Browse repository at this point
Copy the full SHA e5a7495View commit details
Commits on Jan 4, 2019
-
Switch to making final variables context-sensitive
This commit modifies this PR to make selecting the type of final variables context-sensitive. Now, when we do: x: Final = 1 ...the variable `x` is normally inferred to be of type `int`. However, if that variable is used in a context which expects `Literal`, we infer the literal type. This commit also removes some of the hacks to mypy and the tests that the first iteration added.
Configuration menu - View commit details
-
Copy full SHA for 7335991 - Browse repository at this point
Copy the full SHA 7335991View commit details -
Configuration menu - View commit details
-
Copy full SHA for 85fab7d - Browse repository at this point
Copy the full SHA 85fab7dView commit details -
Configuration menu - View commit details
-
Copy full SHA for dd68816 - Browse repository at this point
Copy the full SHA dd68816View commit details -
Configuration menu - View commit details
-
Copy full SHA for 55a38ce - Browse repository at this point
Copy the full SHA 55a38ceView commit details -
Merge branch 'master' into add-literal-final-interactions
# Conflicts: # test-data/unit/check-literal.test
Configuration menu - View commit details
-
Copy full SHA for 118ff58 - Browse repository at this point
Copy the full SHA 118ff58View commit details -
Merge branch 'master' into add-literal-final-interactions
# Conflicts: # test-data/unit/check-literal.test
Configuration menu - View commit details
-
Copy full SHA for d37079c - Browse repository at this point
Copy the full SHA d37079cView commit details -
Merge branch 'add-literal-final-interactions' of github.com:Michael0x…
…2a/mypy into add-literal-final-interactions
Configuration menu - View commit details
-
Copy full SHA for 5969196 - Browse repository at this point
Copy the full SHA 5969196View commit details -
Configuration menu - View commit details
-
Copy full SHA for da6807f - Browse repository at this point
Copy the full SHA da6807fView commit details