SKY-L027 · Logic and resilience
Duplicate string literal
The same string value written out three or more times in one file, such as a status name compared in several functions. SKY-L027 suggests one named constant instead.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans). Only when listed. This is advice outside the default set: the report keeps it in JSON but does not list it, and the gate does not count it, unless you pass
--all-adviceor select the rule (--select SKY-L027). - Finding type
- advice
Why it matters
When the value changes, every copy has to change with it. A missed copy or a typo in one of them is a silent bug: the comparison is simply never true.
What Skylos flags
"""Order status changes for the warehouse API.""" from app.db import Order def ship(order: Order) -> None: if order.status != "awaiting_payment": order.status = "ready_to_ship" order.save() def cancel(order: Order) -> None: if order.status == "awaiting_payment": order.status = "cancelled" order.save() def remind(order: Order) -> bool: return order.status == "awaiting_payment"What Skylos leaves alone
"""Shapes for the order export, the event bus and the audit log.""" def to_row(order) -> dict: return {"customer_id": order.customer_id, "total_cents": order.total} def to_event(order) -> dict: return {"customer_id": order.customer_id, "type": "order.created"} def to_audit(order) -> dict: return {"customer_id": order.customer_id, "action": "create"}Why Skylos leaves it alone
"customer_id" appears three times, but always as a dictionary key: it names a field of a data shape. Skylos does not count dictionary keys, subscripts such as row["customer_id"], or lookups on a known mapping.
How Skylos decides
- Runs with
--qualityon Python files. Skips test, example, benchmark and documentation-build code and the rootsetup.py. - Counts string constants of five characters or more. Leaves out docstrings, f-string pieces, dictionary keys and subscripts,
.get()andinkeys on a mapping it can prove, type annotations andLiteralmembers,cast()type strings,argparsedeclarations, names passed togetattr-style calls, module- and class-level constant tables, file paths, HTML fragments and rule IDs. - Reports a value that is left three or more times; set the limit with
duplicate_stringsunder[tool.skylos]. Codec and URL-scheme names that Python itself knows, such as"utf-8"and"https", are not reported. - The finding points at the first occurrence and records how many functions the copies are in.
- It is advice that is not listed by default.
--all-adviceor--select SKY-L027lists it and lets the gate count it.
How to fix it
Give the value one name and use that name everywhere. An Enum is the next step when the values form a fixed set.
"""Order status changes for the warehouse API.""" from app.db import Order Added: AWAITING_PAYMENT = "awaiting_payment" Added: def ship(order: Order) -> None:Removed: if order.status != "awaiting_payment":Added: if order.status != AWAITING_PAYMENT: order.status = "ready_to_ship" order.save() def cancel(order: Order) -> None:Removed: if order.status == "awaiting_payment":Added: if order.status == AWAITING_PAYMENT: order.status = "cancelled" order.save() def remind(order: Order) -> bool:Removed: return order.status == "awaiting_payment"Added: return order.status == AWAITING_PAYMENTWhen it can be wrong
- Log and error messages that repeat on purpose, such as the same user-facing text in three handlers, are counted.
- Repeated keyword values, for example
on_delete="CASCADE"in several calls, are counted.
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 reported line, the first occurrence.
Python if order.status != "awaiting_payment": # skylos: ignore[SKY-L027] wire value[tool.skylos] ignore = ["SKY-L027"]turns the rule off. To keep it but allow more copies, raiseduplicate_stringsunder[tool.skylos].