Skip to content

FURB118: Should not replace lambda with operator.itemgetter when the itemgetter use the lambda arguments #11573

@nasyxx

Description

@nasyxx

operator.itemgetter cannot be used to replace a lambda function for indexing with lambda arguments.

# xxx.py
xs = [1, 2, 3, 4, 5]

xm = map(lambda x: x[5-x], xs)
xxx.py:
  3:10 FURB118 [*] Use `operator.itemgetter(5-x)` instead of defining a lambda

Here if replaced with operator.itemgetter(5-x), the x would be a undefined variable

ruff: 0.4.5
python: 3.12.2

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions