Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-43224: Add more tests for typevar substitution #31844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

mrahtz
Copy link
Contributor

@mrahtz mrahtz commented Mar 13, 2022

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:

  • I haven't checked how this interacts with Annotated, which @JelleZijlstra thinks there could be some issues with.
  • These don't check for cases where an unpacked arbitrary-length tuple might have to be split between a TypeVar and a TypeVarTuple - e.g. substituting *tuple[int, ...] into T, *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

@serhiy-storchaka
Copy link
Member

I think that it would be better to add these tests in TypeVarTests.test_var_substitution and like, because it will be easy to make it testing the C code.

@mrahtz
Copy link
Contributor Author

mrahtz commented Apr 5, 2022

(I'll close this PR because I'd forgotten it also makes some changes to typing.py. I'll make a new PR that's purely tests-only.)

@mrahtz mrahtz closed this Apr 5, 2022
@mrahtz mrahtz mannequin mentioned this pull request Apr 11, 2022
@mrahtz mrahtz deleted the typevartuple-subst-tests branch May 1, 2022 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants