Skip to content

mypy is unhappy with repeated use of _ as a throw-away variable #1332

@ddfisher

Description

@ddfisher

_ is commonly used as a throw-away variable in list unpacking, but this will make mypy unhappy if two lists with different types are unpacked in the same function. For example

x, _ = ["foo", "bar"]
n, _ = [1, 2]

results in:

test.py:2: error: Incompatible types in assignment (expression has type "int", variable has type "str")

To support this pattern, we may want to consider special-casing _ and not generating this sort of type error if the variable is never read.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions