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

Skip to content

TypeVarTuple example has unused TypeVar #95337

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
adriangb opened this issue Jul 27, 2022 · 1 comment
Closed

TypeVarTuple example has unused TypeVar #95337

adriangb opened this issue Jul 27, 2022 · 1 comment
Labels
docs Documentation in the Doc dir topic-typing

Comments

@adriangb
Copy link
Contributor

From the docs:

Ts = TypeVarTuple('Ts')

def remove_first_element(tup: tuple[Any, *Ts]) -> tuple[*Ts]:
    return tup[1:]

# Ts is bound to ()
# Return value is (), which has type tuple[()]
remove_first_element(tup=(1,))

# Ts is bound to (str,)
# Return value is ('spam',), which has type tuple[str]
remove_first_element(tup=(1, 'spam'))

# Ts is bound to (str, float)
# Return value is ('spam', 3.0), which has type tuple[str, float]
remove_first_element(tup=(1, 'spam', 3.0))

Notice that "T" is only used once in the function signature, which Pylance will highlight as an error.
In this case, Any is just as meaningful as T (and I would argue semantically better, we don't care what the first element is)
All of the examples (checked with reveal_type) are still valid.

@adriangb adriangb added the docs Documentation in the Doc dir label Jul 27, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 30, 2022
Co-authored-by: Alex Waygood <[email protected]>
(cherry picked from commit 07f12b5)

Co-authored-by: Adrian Garcia Badaracco <[email protected]>
JelleZijlstra pushed a commit that referenced this issue Aug 30, 2022
miss-islington added a commit that referenced this issue Aug 30, 2022
Co-authored-by: Alex Waygood <[email protected]>
(cherry picked from commit 07f12b5)

Co-authored-by: Adrian Garcia Badaracco <[email protected]>
@hauntsaninja
Copy link
Contributor

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
docs Documentation in the Doc dir topic-typing
Projects
None yet
Development

No branches or pull requests

3 participants