bpo-43224: Add more tests for typevar substitution by mrahtz · Pull Request #31844 · python/cpython (original) (raw)

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 just int).

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 only typing._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 in TypeVarSubstitutionTests.

These aren't yet complete. In particular:

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