Skip to content

python/comprehension-among-arguments

Rule comprehension-among-arguments
Pack Python
Severity warning
Fix none, edit by hand
Library versions every version

A comprehension that is one of several arguments of a call makes the call hard to read. Give it a name on the line above, and pass the name.

def points(cache, days):
return pd.concat([pd.read_parquet(cache / f"{day}.parquet") for day in days], ignore_index=True)
frames = [pd.read_parquet(cache / f"{day}.parquet") for day in days]
return pd.concat(frames, ignore_index=True)

The rule reports a comprehension or generator expression that is one of several arguments of a call. It leaves a comprehension alone that is the only argument, as in sum(x.cost for x in items).

xpd has no automatic fix, so make the change by hand.

The call holds a loop, and a reader has to find where the loop ends before the other arguments make sense. The name on the line above says what the loop builds, and the call then fits on one short line.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

This comprehension is one of several arguments of a call. Give it a name on the line above, and pass the name.

Browse the other rules of the Python pack.