Ir al contenido

Large collection copy (ARCH2086)

Esta página aún no está disponible en tu idioma.

Key python.performance.large-collection-copy · Severity info · Category performance

Fully materializing a generator with list() just to iterate it pulls every element into memory. Stream over the generator directly instead.

def total_amount(rows):
items = list(r.amount for r in rows)
return sum(items)
def total_amount(rows):
return sum(r.amount for r in rows)

Do not list() generators you only iterate; stream over them directly.