Skip to content

Tuple[A, B] + Tuple[C] = Tuple[Any, …] instead of Tuple[A, B, C] #4604

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
bwo opened this issue Feb 20, 2018 · 1 comment
Closed

Tuple[A, B] + Tuple[C] = Tuple[Any, …] instead of Tuple[A, B, C] #4604

bwo opened this issue Feb 20, 2018 · 1 comment
Labels

Comments

@bwo
Copy link
Contributor

bwo commented Feb 20, 2018

from typing import Tuple 

x = (1, 't', 2)  # type: Tuple[int, str, int]

z = ('t', 3)  # type: Tuple[str, int]

xz = x + z  # type: Tuple[int, str, int, str, int]

Not only is Tuple[Any, …] the inferred type of xz, mypy won't accept the provided annotation:

error: Incompatible types in assignment (expression has type "Tuple[Any, ...]", variable has type "Tuple[int, str, int, str, int]")

Running this program through mypy:

from typing import TypeVar, Type, Mapping, Sequence, Generator, Tuple  # noqa


x = (1, 't', 2)  # type: Tuple[int, str, int]

z = ('t', 3)  # type: Tuple[str, int]

xz = x + z

reveal_type(xz[0])

shows that the type of xz[0] is now Any (consistent with the inferred type).

IMO if it's not type-theoretically onerous the inferred type of xz should be Tuple[int, str, int, str, int].

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 21, 2018

Closing as duplicate of #224.

@JukkaL JukkaL closed this as completed Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants