Skip to main content

SKY-L027 · Logic and resilience

Duplicate string literal

Varies

The catalog gives no severity. A string repeated three to five times is LOW; six times or more is MEDIUM.

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-advice or select the rule (--select SKY-L027).
Finding type
advice
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/orders.py · PythonReported on line 7
"""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

app/exports.py · Python
"""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

  1. Runs with --quality on Python files. Skips test, example, benchmark and documentation-build code and the root setup.py.
  2. Counts string constants of five characters or more. Leaves out docstrings, f-string pieces, dictionary keys and subscripts, .get() and in keys on a mapping it can prove, type annotations and Literal members, cast() type strings, argparse declarations, names passed to getattr-style calls, module- and class-level constant tables, file paths, HTML fragments and rule IDs.
  3. Reports a value that is left three or more times; set the limit with duplicate_strings under [tool.skylos]. Codec and URL-scheme names that Python itself knows, such as "utf-8" and "https", are not reported.
  4. The finding points at the first occurrence and records how many functions the copies are in.
  5. It is advice that is not listed by default. --all-advice or --select SKY-L027 lists 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.

app/orders.py · Python · the fix, against the flagged file
"""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_PAYMENT

When 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, raise duplicate_strings under [tool.skylos].

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.