Large collection copy (ARCH2086)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
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.
Incorrect
Section titled “Incorrect”def total_amount(rows): items = list(r.amount for r in rows) return sum(items)Correct
Section titled “Correct”def total_amount(rows): return sum(r.amount for r in rows)Do not list() generators you only iterate; stream over them directly.