-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Concatenation of tuples #224
Comments
Hi @JukkaL, any update on this feature ? Currently, concatenating two fixed-lengths tuples results in a
|
Unfortunately nobody is working on this and this is not in our near-term roadmap. Adding a priority label so that contributors may be more likely to pick this up. |
Currently the concatenation of two tuples is accepted by mypy but the result has type |
This still give an error when mixing fixed length and homogeneous, see #6337 |
I would like to have support for that feature too. The following code: from typing import *
def d2(x: int, y: int) -> Tuple[int, int]:
return (x, y)
def d3(x: int, y: int, z: int) -> Tuple[int, int, int]:
return d2(x, y) + (z,) results in the mypy error: |
from __future__ import annotations
from enum import Enum, auto
from typing import Literal, Tuple, Union
class AlignScope(Enum):
TABLE = auto()
ROW = auto()
COL = auto()
CELL = auto()
class AlignVert(Enum):
TOP = auto()
BOTTOM = auto()
class AlignHorz(Enum):
LEFT = auto()
RIGHT = auto()
AlignWhat = Union[
Tuple[Literal[AlignScope.TABLE]], # no address
Tuple[Literal[AlignScope.ROW], int], # row index
Tuple[Literal[AlignScope.COL], int], # col index
Tuple[Literal[AlignScope.CELL], int, int], # (row, col)
]
AlignHow = Union[
# align vertically and/or horizontally (non-empty, max. 1× each):
Tuple[AlignVert],
Tuple[AlignHorz],
Tuple[AlignVert, AlignHorz],
Tuple[AlignHorz, AlignVert],
]
# PROPOSAL:
# AlignDirective = AlignWhat + AlignHow
# ...would be equivalent to...
AlignDirective = Union[
Tuple[Literal[AlignScope.TABLE], AlignVert],
Tuple[Literal[AlignScope.TABLE], AlignHorz],
Tuple[Literal[AlignScope.TABLE], AlignVert, AlignHorz],
Tuple[Literal[AlignScope.TABLE], AlignHorz, AlignVert],
Tuple[Literal[AlignScope.ROW], int, AlignVert],
Tuple[Literal[AlignScope.ROW], int, AlignHorz],
Tuple[Literal[AlignScope.ROW], int, AlignVert, AlignHorz],
Tuple[Literal[AlignScope.ROW], int, AlignHorz, AlignVert],
Tuple[Literal[AlignScope.COL], int, AlignVert],
Tuple[Literal[AlignScope.COL], int, AlignHorz],
Tuple[Literal[AlignScope.COL], int, AlignVert, AlignHorz],
Tuple[Literal[AlignScope.COL], int, AlignHorz, AlignVert],
Tuple[Literal[AlignScope.CELL], int, int, AlignVert],
Tuple[Literal[AlignScope.CELL], int, int, AlignHorz],
Tuple[Literal[AlignScope.CELL], int, int, AlignVert, AlignHorz],
Tuple[Literal[AlignScope.CELL], int, int, AlignHorz, AlignVert],
] EDIT: I see now that #224 allows the type of two concatenated tuples to be understood, but does not allow concatenating the types themselves. |
Concatenation of fixed-length tuples should be supported by the type checker.
Arbitrary tuples could be concatenated.
Tuple[int, str] + Tuple[bool]
results inTuple[int, str, bool]
.Concatenating two homogeneous tuples (
Tuple[T, ...]
) already works.The text was updated successfully, but these errors were encountered: