Skip to content

RUF052: Use of dummy variables is not flagged for loop variables #19732

@MichaReiser

Description

@MichaReiser

@AlexWaygood @MichaReiser Searching https://github.com/search?q=repo%3Aastral-sh%2Fruff+RUF052&type=issues does not reveal previous discussions on detecting used dummy variables inside FOR loops and list comprehensions. To avoid extra noise from rushing into opening a new issue, I would like to clarify: Was this rejected somewhere, or was this just not discussed and not implemented yet?

Example:

def no_ruff_warnings():
    my_list = [{"foo": 1}, {"foo": 2}]

    i = 0
    for _ in my_list:
        i += _["foo"]  # A dummy variable is used, but no warnings. 

    for _item in my_list:
        i += _item["foo"]  # A dummy variable is used, but no warnings. 

    [_["foo"] for _ in my_list]  # A dummy variable is used, but no warnings. 

    [_item["foo"] for _item in my_list]  # A dummy variable is used, but no warnings. 

Originally posted by @alessio-locatelli in #14755 (comment)

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcomeruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions