bpo-43224: Add more tests for typevar substitution #31844
Closed
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.
Here are some more tests for the updated type variable substitution logic in #31800 (along with a fix for converting e.g.
*tuple[int]
into justint
).There are existing tests for some of this in e.g.
TypeVarTests.test_var_substitution
, but I think we can keep those tests as something more like integration tests (checking whether substitution is correct on actual aliases), regarding the tests in this PR as something closer to unit tests (testing onlytyping._determine_typevar_substitution
).One thing worth explaining: I've moved the place we call
_check_generic
so that we're doing all the checking for incorrect arity in one place (in_determine_typevar_substitution
). This also makes testing easier - we can test for both correct and incorrect substitutions inTypeVarSubstitutionTests
.These aren't yet complete. In particular:
Annotated
, which @JelleZijlstra thinks there could be some issues with.TypeVar
and aTypeVarTuple
- e.g. substituting*tuple[int, ...]
intoT, *Ts
and*Ts, T
(since I've yet to confirm with @pradeep90 what should even happen in these cases)Even so, I'll put this out there now so that @serhiy-storchaka has a reference of what we need to test for #31828.
https://bugs.python.org/issue43224