GH-87390: Add remaining tests for PEP 646
This PR fixes the last few things from the PEP 646 implementation checklist at https://github.com/python/cpython/issues/87390#issuecomment-1104419757. Specifically:
- Fix a weird hack we used for star-unpacking in
test_genericalias.pybefore the star-unpacking grammar change was merged - Add some more substitution tests (eg
[tuple[*Ts, T][str, *tuple[int, ...]]) - Fix some outdated comments
- Add tests to
typing.pyfor*ed stuff (again, now that the grammar change is merged) - Add tests for
get_originon unpacked stuff
A couple notes:
- If we were being really exhaustive, we would test the cross product of
tuple, Tupleand*, Unpack, for a total of 4 versions of each test, but that would be reeeaaally verbose, so I've gone with just testing the 'new-style' cases (*andtuple) and the 'old-style' cases (UnpackandTuple). -
get_origincurrently gives different behaviour for*tuple[int]andUnpack[tuple[int]]:tuplein the former case,Unpackin the latter. This is a bit inconsistent, but it seems like the least surprising thing from a user's perspective: if I sawUnpack[something], I'd intuitively expected the origin to beUnpack; and if I saw*tuple[something], I'd expect the origin to betuple.
- Issue: gh-87390
Oops, good catch - I think I must have accidentally committed my debug changes, because I found some other things that needed removing. Have fixed them and confirmed that CI is actually passing now :)
@JelleZijlstra Are you happy with these tests? Then you can merge them.
Probably, I'll take another look tonight and merge if I'm happy.
Thanks @mrahtz for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. 🐍🍒⛏🤖
Sorry, @mrahtz and @JelleZijlstra, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker cb95cc24efecf32ad035318867b065a2b042d25a 3.11
GH-98667 is a backport of this pull request to the 3.11 branch.