Skip to content

PERF102 is not detected in generators or comprehensions #6638

@dosisod

Description

@dosisod

PERF102 is not detected in generators or comprehensions, only in for loops:

d = {}

for k, _ in d.items():
    print(k)

_ = (k for k, _ in d.items())
_ = [k for k, _ in d.items()]
_ = {k for k, _ in d.items()}
_ = {k: "v" for k, _ in d.items()}

Running:

$ ruff --version
ruff 0.0.284

$ ruff x.py
x.py:3:13: PERF102 [*] When using only the keys of a dict use the `keys()` method
Found 1 error.
[*] 1 potentially fixable with the --fix option.

Expected: A line for the d.items() call in the generator and each of the list/set/dict comprehension.

Metadata

Metadata

Assignees

Labels

acceptedReady for implementationruleImplementing 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