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
{{ message }}
Repository navigation
x = tuple() # type: Tuple[()] Incompatible types in assignment #6283
testing/resources/builtin_constructors.py:13: error: Incompatible types in assignment (expression has type "Tuple[<nothing>, ...]", variable has type "Tuple[]")
I don't think this is a bug. Every tuple call returns a Tuple[T, ...] for some T, which is not the same as an empty tuple -- it is a tuple containing an arbitrary number of Ts.
Unless you have an actual use case I don't think we should try to special-case calling tuple() without arguments. (It's a class constructor, not a function, so you can't use standard overload syntax to say it returns an empty tuple when called without arguments.)
At some point mypy might support honoring the return type of __new__(), see #1020, so that we will be able to add an overload for empty tuple. We can probably keep this open as a low priority feature.
x = () # type: Tuple[()] works fine. I don't think this is worth any special casing in mypy. We're discussing adding a special case in typeshed instead, though I'm skeptical about that too.
Activity
gvanrossum commentedon Feb 1, 2019
I don't think this is a bug. Every
tuplecall returns aTuple[T, ...]for someT, which is not the same as an empty tuple -- it is a tuple containing an arbitrary number ofTs.Unless you have an actual use case I don't think we should try to special-case calling
tuple()without arguments. (It's a class constructor, not a function, so you can't use standard overload syntax to say it returns an empty tuple when called without arguments.)ilevkivskyi commentedon Feb 1, 2019
At some point mypy might support honoring the return type of
__new__(), see #1020, so that we will be able to add an overload for empty tuple. We can probably keep this open as a low priority feature.[-]`x = tuple() # type: Tuple[()]` Incompatible types in assig nment[/-][+]`x = tuple() # type: Tuple[()]` Incompatible types in assignment[/+]JelleZijlstra commentedon Apr 3, 2022
x = () # type: Tuple[()]works fine. I don't think this is worth any special casing in mypy. We're discussing adding a special case in typeshed instead, though I'm skeptical about that too.