Skip to content

unpacked-list-comprehension (UP027)

Derived from the pyupgrade linter.

Warning: This rule has been removed and its documentation is only available for historical reasons.

Removed

There's no evidence that generators are meaningfully faster than list comprehensions when combined with unpacking.

What it does

Checks for list comprehensions that are immediately unpacked.

Why is this bad?

There is no reason to use a list comprehension if the result is immediately unpacked. Instead, use a generator expression, which avoids allocating an intermediary list.

Example

a, b, c = [foo(x) for x in items]

Use instead:

a, b, c = (foo(x) for x in items)

References