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

x = tuple() # type: Tuple[()] Incompatible types in assignment #6283

Closed
asottile opened this issue Feb 1, 2019 · 3 comments
Closed

x = tuple() # type: Tuple[()] Incompatible types in assignment #6283

asottile opened this issue Feb 1, 2019 · 3 comments

Comments

@asottile
Copy link
Contributor

asottile commented Feb 1, 2019

I understand this is a silly example, but figured I'd report it anyway.

I can't find a way (other than # type: ignore) to silence mypy for this line:

x = tuple()  # type: Tuple[()]

I found #4211 (which is how I got to Tuple[()]

mypy 0.660 errors with:

testing/resources/builtin_constructors.py:13: error: Incompatible types in assignment (expression has type "Tuple[<nothing>, ...]", variable has type "Tuple[]")
@gvanrossum
Copy link
Member

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.)

@ilevkivskyi
Copy link
Member

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.

@asottile asottile changed the title x = tuple() # type: Tuple[()] Incompatible types in assig nment x = tuple() # type: Tuple[()] Incompatible types in assignment Aug 18, 2019
@JelleZijlstra
Copy link
Member

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.

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

No branches or pull requests

4 participants