You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came up with this when trying to fix itertools.combinations in typeshed to be a class instead of function.
It seems like mypy doesn't consider Tuple[T,T] to not overlap with Tuple[T, ...] with regards to return type.
I'm not sure if this is a bug or policy, but I would think that a variable length tuple is basically a union of all set length tuples and therefore should accept this.
To Reproduce
See the following code:
`
from typing import Generic, Literal, Tuple, overload,TypeVar
_T = TypeVar("_T")
class A(Generic[_T]): @overload
def new(cls, a: Literal[1]) -> A[Tuple[int]]:
... @overload
def new(cls, a: int) -> A[Tuple[int, ...]]:
...
def new(cls, a: int) -> A[Tuple[int, ...]]:
return super().new(cls)
`
mypy returns the following error:
error: Overloaded function signatures 1 and 2 overlap with incompatible return types
(also some error for the implementation return type, but it's irrelevant).
Your Environment
latest mypy, python 3.8.
Tried also on mypy playground with latest mypy and 3.9.
The text was updated successfully, but these errors were encountered:
hatal175
changed the title
Variable length tuples incompatible with set length tuples with regards to return type
Incompatible return type for overlapping signatures with regards to __new__
Apr 12, 2021
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
I came up with this when trying to fix itertools.combinations in typeshed to be a class instead of function.
It seems like mypy doesn't consider Tuple[T,T] to not overlap with Tuple[T, ...] with regards to return type.
I'm not sure if this is a bug or policy, but I would think that a variable length tuple is basically a union of all set length tuples and therefore should accept this.
To Reproduce
See the following code:
`
from typing import Generic, Literal, Tuple, overload,TypeVar
_T = TypeVar("_T")
class A(Generic[_T]):
@overload
def new(cls, a: Literal[1]) -> A[Tuple[int]]:
...
@overload
def new(cls, a: int) -> A[Tuple[int, ...]]:
...
def new(cls, a: int) -> A[Tuple[int, ...]]:
return super().new(cls)
`
mypy returns the following error:
error: Overloaded function signatures 1 and 2 overlap with incompatible return types
(also some error for the implementation return type, but it's irrelevant).
Your Environment
latest mypy, python 3.8.
Tried also on mypy playground with latest mypy and 3.9.
The text was updated successfully, but these errors were encountered: