Skip to content

TypeVarTuple.__typing_prepare_subst__ does not work as intented #96385

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
sobolevn opened this issue Aug 29, 2022 · 1 comment
Closed

TypeVarTuple.__typing_prepare_subst__ does not work as intented #96385

sobolevn opened this issue Aug 29, 2022 · 1 comment
Assignees
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Aug 29, 2022

Right now there's an uncovered branch in TypeVarTuple.__typing_prepare_subst__:

Снимок экрана 2022-08-29 в 15 16 14

And it looks like there's a bug in it, these two lines:

        for param in enumerate(params[typevartuple_index + 1:]):
            if isinstance(param, TypeVarTuple):

This if's body will never be executed, because enumerate always returns tuple[int, T], it is never TypeVarTuple.

So, I think that we need to remove enumerate() call here and add a test like:

>>> from typing import Generic, TypeVarTuple
>>> V = TypeVarTuple('V')
>>> T = TypeVarTuple('T')
>>> class My(Generic[*T]): pass
... 
>>> My[*T, *V][*V]
TypeError: More than one TypeVarTuple parameter in __main__.My[*T, *V]

I will send a PR 😉

@sobolevn sobolevn added the type-bug An unexpected behavior, bug, or error label Aug 29, 2022
@sobolevn sobolevn self-assigned this Aug 29, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Aug 29, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 30, 2022
pablogsal pushed a commit that referenced this issue Aug 30, 2022
…#96407)

(cherry picked from commit 7517735)

Co-authored-by: Nikita Sobolev <[email protected]>

Co-authored-by: Nikita Sobolev <[email protected]>
@hauntsaninja
Copy link
Contributor

Thanks for spotting this, looks like this has been completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants