Created
February 12, 2026 14:06
-
-
Save mypy-play/2a9def866495688f257f1839bdc1634a to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Any, Protocol, assert_type | |
| class WithTuple[*Ts](Protocol): | |
| tup: tuple[*Ts] | |
| def get_tuple[*Ts](e: WithTuple[*Ts]) -> tuple[*Ts]: | |
| return e.tup | |
| def get_first[T](e: WithTuple[T, *tuple[Any, ...]]) -> T: | |
| return e.tup[0] | |
| class X: | |
| tup: tuple[int, str] | |
| assert_type(get_tuple(X()), tuple[int, str]) | |
| assert_type(get_first(X()), int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment