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

Support variadic tuple packing/unpacking #16205

Merged
merged 10 commits into from
Oct 8, 2023

Conversation

ilevkivskyi
Copy link
Member

This is includes also related things such as tuple concatenation, special-cased tuple "re-packing", and star tuple unpacking in homogeneous collections.

It looks like we are very close to the finish line (the only major missing feature is type narrowing using len(), apart from this I just need to do couple technical things, and make one final search for missed code paths).

Some notes:

  • Unfortunately, star items on l.h.s create lists at runtime. This means there are various cases where list[object] is the best type we can have.
  • Note I now infer "precise" types for expressions like (x, *y, z), where y is say tuple[int, ...]. This may cause errors for code that previously worked (when we will turn this feature on). For example (1, *[], 2)[42] will be an error. As usual, I propose to try to be strict, and relax if people will complain (FWIW, I expect very few false positives from this).
  • It may look like Unpack can now "leak" if it was never used explicitly. This is not the case, it is just that experimental features are enabled in tests.
  • There are couple minor changes that affect code without variadic types. Previously tuple type context was used inconsistently for situations with star unpacks, I clean it up a bit (for my tests). Also I infer Any-like l.h.s types after an error in tuple unpacking (when needed) to avoid extra "Cannot determine type" errors in my tests.

@mehdigmira If you are still not tired doing this, please check this PR as usual.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

kornia (https://github.com/kornia/kornia)
+ kornia/feature/loftr/utils/coarse_matching.py:238: error: Unused "type: ignore" comment  [unused-ignore]

spark (https://github.com/apache/spark)
+ python/pyspark/pandas/typedef/typehints.py:783: error: Unused "type: ignore[has-type]" comment  [unused-ignore]

@ilevkivskyi
Copy link
Member Author

@JukkaL @jhance I have been waiting more than a week here, so I am going to merge this now. If you have some comments, I can address them separately later.

@ilevkivskyi ilevkivskyi merged commit d54e8b3 into python:master Oct 8, 2023
18 checks passed
@ilevkivskyi ilevkivskyi deleted the variadic-tuple-unpack branch October 8, 2023 18:32
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.

2 participants