Skip to content

False positive undefined-loop-variable in function signature when the typing match a variable name #5480

Open
@Pierre-Sassoulas

Description

@Pierre-Sassoulas

Bug description

Consider the following file a.py

from typing import List


def parse_dict(dict_object: List[dict], name: str) -> dict:
    for dict in dict_object:
        if dict.get("name") == name:
            return dict
    return {}

Command used

pylint a.py

Pylint output

************* Module a
a.py:4:33: W0631: Using possibly undefined loop variable 'dict' (undefined-loop-variable)
a.py:4:54: W0631: Using possibly undefined loop variable 'dict' (undefined-loop-variable)

Expected behavior

No warning.

Pylint version

pylint 2.12.2
astroid 2.9.0
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions