-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Binary arithmetic on nested Unions of numeric types fails to typecheck #8125
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
Comments
As a workaround, if I manually "flatten" the from typing import Union
T3 = Union[int, float, complex]
def bar(a: T3, b: T3) -> T3:
return a + b # ok |
It looks like the issue is that in Interested in submitting a PR? |
Not at this time, no. I spent a few minutes looking into it, but being new to the mypy codebase, I suspect it'll take longer than I want to spend on it. For now, I'm happy to stick with mypy 0.740. Here are some notes in case it's useful for whoever picks this up (maybe future me). Warning: I have no understanding of mypy internals and didn't attempt to properly debug this, just skimmed the source code. At first I was confused because Since my example above is using nested type aliases, I assume these get turned into Following on with @msullivan's tip about
I'm am not sure what the right fix would be here, whether it's (a) flattening nested type alias Unions "by hand" in |
Resolves #8125 The main problem is not about flattening unions inside variants since the following code generates no error ```python from typing import Union T1 = Union[int, float] T2 = Union[Union[Union[int, float], float], Union[float, complex], complex] def foo(a: T2, b: T2) -> T2: return a + b ``` The problem, however, is because when using `TypeAliasType` to alias a Union, the `TypeAliasType` will not get flattened, so this PR fixes this.
Are you reporting a bug, or opening a feature request?
bug (I think)
Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal repro.
What is the actual behavior/output?
What is the behavior/output you expect?
To typecheck without errors.
What are the versions of mypy and Python you are using? Do you see the same issue after installing mypy from Git master?
python 3.6.9
mypy 0.750 and master produce the above error.
mypy 0.740 does not produce an error.
What are the mypy flags you are using? (For example --strict-optional)
The issue reproduces when running mypy both without any flags and when running with
--strict
.Additional info
In case it's helpful, here are some possibly/loosely-related issues I found while searching the issue tracker:
#2128
#3196
The text was updated successfully, but these errors were encountered: