Skip to main content

SKY-L038 · Logic and resilience

Conversion call inside f-string

Low

An f-string field that calls str(), repr() or ascii(), such as f"Order {str(order.id)}". f-strings have conversion flags for exactly this: {order.id!s}, {order.id!r} and {order.id!a}.

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-L038).
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

The call is longer than the flag and does the same thing. It is a small readability cost, but it adds up in logging and message code, and it is a common sign of code converted from % or .format() style by hand.

What Skylos flags

shipping/notify.py · PythonReported on line 5
"""Shipping notifications."""  def shipped_message(order):    return f"Order {str(order.id)} shipped to {order.city}"

What Skylos leaves alone

shipping/notify.py · Python
"""Shipping notifications."""  def shipped_message(order):    return f"Order {str(order.id).zfill(8)} shipped to {order.city}"

Why Skylos leaves it alone

str() is called to get a string for .zfill(8), not as the whole field. A conversion flag cannot express that, so there is nothing to replace.

How Skylos decides

  1. Runs with --quality on Python files. Looks at every f-string field that has no conversion flag yet.
  2. Reports a field whose whole expression is str(x), repr(x) or ascii(x) with one plain argument, where the name resolves to the builtin (a local def str, a parameter or an assignment named str turns the check off).
  3. Reads the source to make sure the field ends with } or :, so debug fields such as {str(x)=} are not reported: there the expression text is part of the output.
  4. Skips files where the project's ruff configuration ignores RUF010, and golden test fixtures. Reports LOW on the line of the call.

How to fix it

Use the conversion flag. For str(), {order.id} alone is usually enough, since an f-string field already formats the value as text.

shipping/notify.py · Python · the fix, against the flagged file
"""Shipping notifications."""  def shipped_message(order):Removed:     return f"Order {str(order.id)} shipped to {order.city}"Added:     return f"Order {order.id!s} shipped to {order.city}"

When it can be wrong

  • This is style advice; the code works. Teams that find str() easier to read than !s can turn the rule off.

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.

    Python
    label = f"{str(item)}"  # skylos: ignore[SKY-L038] matches the legacy format
  • [tool.skylos] ignore = ["SKY-L038"] turns the rule off for the project. Ignoring ruff's RUF010 in the project's ruff configuration also turns it off.

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