Skip to content

"object" has no attribute "__iter__" false-positive #8706

Closed
@tucked

Description

@tucked
# sscce.py


def no_repro(bar: str = '4'):
    key_values = {
        'key': [1, 2, 3],
        'key2': [1, 2],
    }
    return all(
        value
        for key, values in key_values.items()
        for value in values
    )


def repro(bar: str = '4'):
    key_values = {
        'key': [1, 2, 3, bar],  # <--- bar is included
        'key2': [1, 2],
    }
    return all(
        value
        for key, values in key_values.items()
        for value in values
    )
  • Note: no repro without 'key2': [1, 2],
mypy sscce.py
sscce.py:21: error: "object" has no attribute "__iter__"; maybe "__str__" or "__dir__"? (not iterable)
Found 1 error in 1 file (checked 1 source file)
  • Python 3.6.8
  • mypy 0.770 (mypy-0.770+dev.833fc2caec6773683d691a72058293ae87139210 too)

Potentially related: #4975

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