-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Input code:
def output_table(rows):
amax = max(len(row) for row in rows)
for row in rows:
row.extend("" for _ in range(amax - len(row)))
lens = [max(strcol(v) for v in col) for col in zip(*rows)]
print(
"\n".join(
" ".join(
"{{{0}:<{1}}}".format(i, alen - (strcol(v) - len(v)))
for i, (alen, v) in enumerate(zip(lens, row)) # << use 1 of `row`
).format(*row) # << use 2 of `row`
for row in rows
)
)Command: ruff check --isolated --select FURB140 --preview --fix example.py
Resulting code after autofix:
from itertools import starmap
# ...
def output_table(rows):
amax = max(len(row) for row in rows)
for row in rows:
row.extend("" for _ in range(amax - len(row)))
lens = [max(strcol(v) for v in col) for col in zip(*rows)]
print(
"\n".join(
starmap(
" ".join(
"{{{0}:<{1}}}".format(i, alen - (strcol(v) - len(v)))
for i, (alen, v) in enumerate(zip(lens, row)) # << `row` is no longer defined here
).format,
rows,
)
)
)Note how the original generator comprehension had two uses use of the row loop variable, but the autofix only replaces one of them with the starmap, which breaks the code.
Ruff version: ruff 0.4.8
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working