---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF017 [*] Avoid quadratic list summation
 --> RUF017_0.py:5:1
  |
4 | # RUF017
5 | sum([x, y], start=[])
  | ^^^^^^^^^^^^^^^^^^^^^
6 | sum([x, y], [])
7 | sum([[1, 2, 3], [4, 5, 6]], start=[])
  |
help: Replace with a starred list comprehension
  |
4 | # RUF017
  - sum([x, y], start=[])
5 + [*sublist for sublist in [x, y]]
6 | sum([x, y], [])
  |
note: This is an unsafe fix and may change runtime behavior

RUF017 [*] Avoid quadratic list summation
 --> RUF017_0.py:6:1
  |
4 | # RUF017
5 | sum([x, y], start=[])
6 | sum([x, y], [])
  | ^^^^^^^^^^^^^^^
7 | sum([[1, 2, 3], [4, 5, 6]], start=[])
8 | sum([[1, 2, 3], [4, 5, 6]], [])
  |
help: Replace with a starred list comprehension
  |
5 | sum([x, y], start=[])
  - sum([x, y], [])
6 + [*sublist for sublist in [x, y]]
7 | sum([[1, 2, 3], [4, 5, 6]], start=[])
  |
note: This is an unsafe fix and may change runtime behavior

RUF017 [*] Avoid quadratic list summation
 --> RUF017_0.py:7:1
  |
5 | sum([x, y], start=[])
6 | sum([x, y], [])
7 | sum([[1, 2, 3], [4, 5, 6]], start=[])
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 | sum([[1, 2, 3], [4, 5, 6]], [])
9 | sum([[1, 2, 3], [4, 5, 6]],
  |
help: Replace with a starred list comprehension
  |
6 | sum([x, y], [])
  - sum([[1, 2, 3], [4, 5, 6]], start=[])
7 + [*sublist for sublist in [[1, 2, 3], [4, 5, 6]]]
8 | sum([[1, 2, 3], [4, 5, 6]], [])
  |
note: This is an unsafe fix and may change runtime behavior

RUF017 [*] Avoid quadratic list summation
  --> RUF017_0.py:8:1
   |
 6 | sum([x, y], [])
 7 | sum([[1, 2, 3], [4, 5, 6]], start=[])
 8 | sum([[1, 2, 3], [4, 5, 6]], [])
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 9 | sum([[1, 2, 3], [4, 5, 6]],
10 |     [])
   |
help: Replace with a starred list comprehension
  |
7 | sum([[1, 2, 3], [4, 5, 6]], start=[])
  - sum([[1, 2, 3], [4, 5, 6]], [])
8 + [*sublist for sublist in [[1, 2, 3], [4, 5, 6]]]
9 | sum([[1, 2, 3], [4, 5, 6]],
  |
note: This is an unsafe fix and may change runtime behavior

RUF017 [*] Avoid quadratic list summation
  --> RUF017_0.py:9:1
   |
 7 |   sum([[1, 2, 3], [4, 5, 6]], start=[])
 8 |   sum([[1, 2, 3], [4, 5, 6]], [])
 9 | / sum([[1, 2, 3], [4, 5, 6]],
10 | |     [])
   | |_______^
11 |
12 |   # OK
   |
help: Replace with a starred list comprehension
   |
8  | sum([[1, 2, 3], [4, 5, 6]], [])
   - sum([[1, 2, 3], [4, 5, 6]],
   -     [])
9  + [*sublist for sublist in [[1, 2, 3], [4, 5, 6]]]
10 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF017 [*] Avoid quadratic list summation
  --> RUF017_0.py:21:5
   |
19 |     import functools, operator
20 |
21 |     sum([x, y], [])
   |     ^^^^^^^^^^^^^^^
   |
help: Replace with a starred list comprehension
   |
20 |
   -     sum([x, y], [])
21 +     [*sublist for sublist in [x, y]]
22 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF017 [*] Avoid quadratic list summation
  --> RUF017_0.py:26:5
   |
24 | # Regression test for: https://github.com/astral-sh/ruff/issues/7718
25 | def func():
26 |     sum((factor.dims for factor in bases), [])
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Replace with a starred list comprehension
   |
25 | def func():
   -     sum((factor.dims for factor in bases), [])
26 +     [*sublist for sublist in (factor.dims for factor in bases)]
   |
note: This is an unsafe fix and may change runtime behavior
