-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations
Description
PERF401 is triggered on code that has the walrus operator inside. The walrus operator is not available in the list-comprehension if-shorthand and it can not be recreated within a single list-comprehension.
Minimal example
items = []
for i in range(5):
if j := i:
items.append(j)This code can obviously be refactored to not include the walrus operator but there are more complex scenarios where it is impossible to do so without using multiple list-comprehensions or duplicating code.
More complex example
import re
items = []
for s in ["abc", "cde", "efg"]:
if match := re.match(r"e[a-z]+", s):
items.append(match.group(0))Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations