-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Disable promotions in isinstance checks #6114
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
Disable promotions in isinstance checks #6114
Conversation
This pull request resolves python#6060 by modifying `conditional_type_map` function in `checker.py` to ignore promotions.
Note: I am somewhat suspicious of this solution. I'll try testing it on our internal codebases later today or tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a right change. You can merge this after verifying this works well with internal code bases.
This does actually cause some trouble in internal code bases (with |
The type of Num.n is `complex`, though it can in practice also be an `int` or a `float`, and we case on the actual type to determine which sort of mypy ast node to use. In #6114, promotions were disabled in `isinstance` checks, which caused mypy to decide that the `isinstance` checks for int and float won't match. Fix this by giving the value the type object instead of complex. Typeshed *does* actually annotate `n` as `Union[float, int, complex]`, but mypy simplifies that into `complex`. (It does *not* do this simplification for local variables with such an annotation; see issue #6168.)
The type of Num.n is `complex`, though it can in practice also be an `int` or a `float`, and we case on the actual type to determine which sort of mypy ast node to use. In #6114, promotions were disabled in `isinstance` checks, which caused mypy to decide that the `isinstance` checks for int and float won't match. Fix this by giving the value the type object instead of complex. Typeshed *does* actually annotate `n` as `Union[float, int, complex]`, but mypy simplifies that into `complex`. (It does *not* do this simplification for local variables with such an annotation; see issue #6168.)
This pull request reverts python#6114 and python#6142: see python#6180 for rationale. In short, the original fix ended up being more disruptive then anticipated: it's modifying str and unicode semantics, and we should put a little more thought into reasoning about that particular case before moving ahead with any fix here. This should also help unblock the upcoming 0.660 release.
This pull request reverts #6114 and #6142: see #6180 for rationale. In short, the original fix ended up being more disruptive then anticipated: it's modifying str and unicode semantics, and we should put a little more thought into reasoning about that particular case before moving ahead with any fix here. This should also help unblock the upcoming 0.660 release.
This pull request resolves #6060 by modifying
conditional_type_map
function inchecker.py
to ignore promotions.