Skip to content

Type errors using (x, _, _) = (1, 2, "3") #1649

Closed

Description

@timabbott

It's a common pattern to use assignment to _ in code to ignore variables that aren't used, and mypy doesn't support that:

/home/tabbott/foo.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int")

In my real code the usage looks more like this:

for (email, _, _, _) in users:                                                                                                                                     
    ...

Not sure whether the right answer is to change the code, but I think I'd flag this as an interesting case that may be somewhat common.

Activity

  1. gvanrossum commented on Jun 4, 2016

    @gvanrossum
    Member

    It's common enough to flag a few variable names as special as targets: _, __, and unused have all been recommended at various times.

  2. JelleZijlstra commented on Jul 1, 2017

    @JelleZijlstra
    Member

    This is a duplicate of #465.

  3. ilevkivskyi commented on Jul 1, 2017

    @ilevkivskyi
    Member

    Yes, it looks like this is a duplicate. I think it makes sense to only keep one of them open.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions