Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Description
Bug Report
mypy does not use the information is has about the types in a tuple effectively when iterating through the tuple's values.mypy does not allow a function that can handle every type in the tuple to be called on the tuples values.mypy will check only if the function supports the closest common parent class of all types in the tuple.
To Reproduce
classA: ...classB: ...deffunction(x:A|B)->None:returnt:tuple[A,B]= (A(),B())forxint:function(x)
https://gist.github.com/mypy-play/671835ea899ca94ddd33150f155fbc39
Expected Behavior
We would expectmypy to approve the code. Logicallyfunction() can never be called with a value that conflicts with the type hints of its parameterx.
Actual Behavior
mypy exits with an error, even though the code is perfectly safe to run in terms of passing valid types with certainty.
main.py:14: error: Argument 1 to "function" has incompatible type "object"; expected "A | B" [arg-type]Found 1 error in 1 file (checked 1 source file)Your Environment
We used amypy Playground set up with no defaults changed:
- Mypy version used:
1.5.1(latest) - Mypy command-line flags:
none - Mypy configuration options from
mypy.ini(and other config files):none - Python version used:
3.11