Skip to content

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

Closed

Description

@asottile

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[]")

Activity

  1. gvanrossum commented on Feb 1, 2019

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

  2. ilevkivskyi commented on Feb 1, 2019

    @ilevkivskyi
    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.

  3. changed the title [-]`x = tuple() # type: Tuple[()]` Incompatible types in assig nment[/-] [+]`x = tuple() # type: Tuple[()]` Incompatible types in assignment[/+] on Aug 18, 2019
  4. JelleZijlstra commented on Apr 3, 2022

    @JelleZijlstra
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions