-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type inference of Tuples returns object instead #4975
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
Yes, this looks like a bug. Most likely it is because join of tuples is still pretty basic (in particular a case of joining fixed length tuple and variable length tuple is not covered). |
A simple repro: x: Tuple[int, int]
y: Tuple[int, ...]
lst = [x, y]
reveal_type(lst[0]) # Revealed type is 'builtins.object*' Clearly the type should be |
Is this fix available in a release yet? |
@beamerblvd I'm not sure I understand. I don't think there is a fix for this yet |
@ethanhs, my mistake. I saw a red |
This already appeared five times, so I am raising priority to high (especially since IIUC we are not going to infer unions for ternary expressions). This should be not hard to fix if someone wants to try. |
These are due to the bug at python/mypy#4975.
Another minimal reproducer: tup1: tuple = ()
tup2 = tup1 if input() else ()
reveal_type(tup2) # N: Revealed type is 'builtins.object' What is even happening here? 😄 |
@intgr the underlying problem is that internally in mypy, the types for fixed-length tuples (like |
For example: Tuple[bool, int] + Tuple[bool] becomes Tuple[int, ...] Previously Mypy simply punted and returned `object`. This solves part of #4975.
@intgr Do you think that this issue can be closed now, after you've PRs were merged? |
Yes, that should solve all the cases involving tuples. Also #8074 can be closed, as it falls back to |
Closing as it was fixed in #8335. I'm very happy to see this issue fixed :) |
While interacting with
zip
I encountered a variant of the following error:which is emitted by mypy on the case of
This code runs normally on python 3.6.5, outputting:
Expected Behavior
Mypy should infer that
ordered_item
is a tuple, or at least an iterable so thatzip
can be applied on it.It may also be interesting to consider the case where
ordered_item
is heterogenous over differentIterables
(i.e. not only tuples). Would Iterable be inferred then?Actual Behavior
Mypy infers the
object
type onordered_item
which you understandably cannot zip.By explicitly casting
item
to tuple the error message is resolved:Environment
OS: macOS 10.13
Python: 3.6.5
mypy: 0.590
The text was updated successfully, but these errors were encountered: