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

Don't consider a branch unreachable if there is possible promotion #14077

Merged
merged 3 commits into from
Nov 14, 2022

Conversation

ilevkivskyi
Copy link
Member

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_primer will show.

@github-actions

This comment has been minimized.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I'd expected this to also give int. What happens if x is a union with an unrelated type, like complex | str?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link
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

@ilevkivskyi
Copy link
Member Author

If there are no more comments, I am going to merge this later today or tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.990 regression with implicit complex/int promotion
2 participants