SKY-L034 · Logic and resilience
Repeated mutable alias
A list built by repeating a list that holds a mutable value, such as [[None] * cols] * rows or [{}] * 3. The * copies references, not values, so every row is the same inner list.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- defect
Why it matters
A change to one element shows up in all of them. In the example below, booking seat 3 in row 0 books seat 3 in every row, and the venue shows as sold out after a handful of sales.
What Skylos flags
"""Seat maps for a venue.""" def empty_seat_map(rows, seats_per_row): return [[None] * seats_per_row] * rows def book(seat_map, row, seat, ticket_id): seat_map[row][seat] = ticket_idWhat Skylos leaves alone
"""Seat maps for a venue.""" def empty_row(seats_per_row): return [None] * seats_per_row def book(row_map, seat, ticket_id): row_map[seat] = ticket_idWhy Skylos leaves it alone
The repeated element is None, which cannot be changed in place. row_map[seat] = ticket_id replaces one slot and leaves the others alone, so sharing the same None is harmless.
How Skylos decides
- Runs with
--qualityon Python files. Looks at every*whose one side is a list or tuple literal (or a+or*of such literals) and whose other side is the repeat count. - The sequence must provably contain a mutable element: a list, dict or set literal or comprehension, a call to builtin
list(),dict()orset()that is not shadowed in the file, a list repetition such as[None] * cols, or a tuple holding one of these. - The count must be able to be 2 or more. A literal
0or1, a comparison, anotexpression and a builtinbool()result are skipped; an unknown name such asrowscounts. - Reports MEDIUM on the line of the
*expression.
How to fix it
Build each inner list separately with a comprehension, so every row is its own object.
"""Seat maps for a venue.""" def empty_seat_map(rows, seats_per_row):Removed: return [[None] * seats_per_row] * rowsAdded: return [[None] * seats_per_row for _ in range(rows)] def book(seat_map, row, seat, ticket_id): seat_map[row][seat] = ticket_idWhen it can be wrong
- A grid that is only ever read, never changed in place, is still reported; the sharing is harmless there.
- It misses repetition of a variable that holds a list, such as
row = []followed by[row] * 3, because only literals and builtin calls written in place are proven mutable.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line of the
*expression.Python EMPTY = [[]] * 4 # skylos: ignore[SKY-L034] read-only sentinel rows[tool.skylos] ignore = ["SKY-L034"]turns the rule off for the project.