Extend support for tuple subtyping with typevar tuples #13718
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new Pep646 test case which demonstrates that like with the constraints from PR #13716 we need to split twice for subtyping when handling Unpacks.
It also demonstrates a weakness of the previous PR which is that the middle-prefix and the prefix may need to be handled differently so we introduce another splitting function that returns a 10-tuple instead of a 6-tuple and reimplement the 6-tuple version on top of the 10-tuple version.
Complicating things further, the test case reveals that there are error cases where split_with_mapped_and_template cannot actually unpack the middle a second time because the mapped middle is too short to do the unpack. We also now have to deal with the case where there was no unpack in the template in which case we only do a single split.
In addition we fix a behavioral issue where according to PEP646 we should assume that Tuple[Unpack[Tuple[Any, ...]]] is equivalent to Tuple[Any, Any] even if we don't actually know the lengths match. As such test_type_var_tuple_unpacked_variable_length_tuple changes from asserting a strict subtype to asserting equivalence.
One of the messages was bad as well so we add a branch for UnpackType in message pretty-printing.