Skip to content

False reports on W0644 unbalanced-dict-unpacking in pylint 2.16.0 #8156

@Spindel

Description

@Spindel

Bug description

When unpacking while iterating over dict.values() we seem to get a spurious warning about unbalanced dict unpacking.

Here's a test-case, result vs. result1 may require a few changes to the types, but the original code was doing a lot more dynamic things with callbacks and more.

from typing import Dict, Tuple, Callable

Inner = Callable[[int], Dict[str, int]]

def returns_dict(a:int, b:int) -> Dict[str, Tuple[int, int, int]]:
    result1 = {
        "abcdef": returns_things(a, b, "abcdef"),
        "cdef": returns_other_things(a,b, "cdef"),
    }
    result = {
        "abc": (1, 2, 3),
        "cde": (1, 2, 3),
    }
    return result

def returns_things(a:int, b:int, c:str) -> Tuple[str, str, Inner]:
    def inner(other: int) -> Dict[str, int]:
        return {"called": other}
    return f"{a}{b}", c, inner


def returns_other_things(a:int, b:int, c:str)  -> Tuple[str, str, Inner]:
    def inner(other: int) -> Dict[str, int]:
        return {"called": other}
    return f"{1}{c}", c, inner


def thing(a:int, b:int) -> None:
    bar = returns_dict(a, b)
    [print(x) for x in bar.values()]
    for x, y, _z in bar.values():
        assert x
        assert y

if __name__ == "__main__":
    thing(1, 2)

Configuration

No response

Command used

pylint pylint_testcase.py

Pylint output

************* Module pylint_testcase
pylint_testcase.py:32:4: W0644: Possible unbalanced dict unpacking with bar.values(): left side has 3 labels, right side has 2 values (unbalanced-dict-unpacking)

Expected behavior

No warning should happen

Pylint version

pylint 2.16.0
astroid 2.14.1
Python 3.11.1 (main, Jan  6 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]

OS / Environment

Fedora 37, x86_64

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions