X Tutup
The Wayback Machine - https://web.archive.org/web/20201019100847/https://github.com/python/typing/issues/692
Skip to content
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

Multiple types for variable-length Tuples #692

Open
rggjan opened this issue Dec 12, 2019 · 2 comments
Open

Multiple types for variable-length Tuples #692

rggjan opened this issue Dec 12, 2019 · 2 comments

Comments

@rggjan
Copy link

@rggjan rggjan commented Dec 12, 2019

After #30 is supported, it would be great if variable-length Tuples would also work with multiple types.

For example, a Tuple with a string and zero or more ints inside could look like this:

Tuple[str, int, ...]

which currently can only be expressed as:

Tuple[Any, ...]

@arseniiv
Copy link

@arseniiv arseniiv commented Jan 7, 2020

Supporting at least the subset of types of the form Tuple[T1, T2, <some Ts>, TRest, ...] — that is, with ... allowed only in final position and only once (specifically not including things like Tuple[int, ..., str, bool] or Tuple[str, ..., int, ...] which too can have their merits) — seems more or less reasonable to me. (Seen this kinds of types in Ceylon language, though there tuple/tuple-like types are intristically linked with callable types, and there is more reason for these that may be here.) Not including the kinds of types in parentheses should ease typechecking, as far I understand it.

I see at least one weak use in DSL design: writing values of the allowed type Tuple[str, List[int]] (contrived) is a bit more tedious than writing values of Tuple[str, int, ...] instead. Maybe there is even a non-contrived example. :)

It can be argued that if tuple concatenation types for the tuple types postulated today, will become typable in e. g. MyPy or other major typecheckers, then the proposed kind of tuples may be a pain to cover.

@rggjan
Copy link
Author

@rggjan rggjan commented Jan 8, 2020

Thanks @arseniiv . Just to add to this, my use case is a function in a class which returns a Tuple[Foo, Any, ...].
This class is meant to be subclassed and the function overridden. All subclasses have to return Foo as the first element in the Tuple, but can choose to add 0 or more additional elements, depending on the subclass usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
X Tutup