Don't consider a branch unreachable if there is possible promotion#14077
Merged
ilevkivskyi merged 3 commits intopython:masterfrom Nov 14, 2022
Merged
Don't consider a branch unreachable if there is possible promotion#14077ilevkivskyi merged 3 commits intopython:masterfrom
ilevkivskyi merged 3 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
Member
JelleZijlstra
left a comment
There was a problem hiding this comment.
Thanks for working on this!
Note that a few tests are failing.
| x: Union[float, complex] | ||
| if isinstance(x, int): | ||
| # Most likely this was an error, but we still type-check this branch | ||
| reveal_type(x) # N: Revealed type is "<nothing>" |
Member
There was a problem hiding this comment.
hm, I'd expected this to also give int. What happens if x is a union with an unrelated type, like complex | str?
Member
Author
There was a problem hiding this comment.
It will be also <nothing>. It is not easy to change. I however discovered couple more bugs while playing with this, so I will try to figure out something.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: flake8-pyi (https://github.com/PyCQA/flake8-pyi)
- pyi.py:1126: error: Subclass of "complex" and "int" cannot exist: would have incompatible method signatures [unreachable]
- pyi.py:1275: error: Subclass of "complex" and "int" cannot exist: would have incompatible method signatures [unreachable]
- pyi.py:1275: error: Right operand of "and" is never evaluated [unreachable]
- pyi.py:1276: error: Statement is unreachable [unreachable]
- pyi.py:1287: error: Subclass of "complex" and "int" cannot exist: would have incompatible method signatures [unreachable]
- pyi.py:1288: error: Right operand of "and" is never evaluated [unreachable]
- pyi.py:1290: error: Statement is unreachable [unreachable]
- pyi.py:1313: error: Subclass of "complex" and "int" cannot exist: would have incompatible method signatures [unreachable]
core (https://github.com/home-assistant/core)
+ homeassistant/components/gios/__init__.py:33: error: Unused "type: ignore" comment
|
JelleZijlstra
approved these changes
Nov 13, 2022
Member
Author
|
If there are no more comments, I am going to merge this later today or tomorrow. |
This was referenced Nov 14, 2022
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #14030
FWIW this looks like an acceptable compromise after discussions in the issue. Also it is easy to implement. Let's see what
mypy_primerwill show.