Skip to content

Support variadic tuple packing/unpacking#16205

Merged
ilevkivskyi merged 10 commits intopython:masterfrom
ilevkivskyi:variadic-tuple-unpack
Oct 8, 2023
Merged

Support variadic tuple packing/unpacking#16205
ilevkivskyi merged 10 commits intopython:masterfrom
ilevkivskyi:variadic-tuple-unpack

Conversation

@ilevkivskyi
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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