SKY-L038 · Logic and resilience
Conversion call inside f-string
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-adviceor select the rule (--select SKY-L038). - Finding type
- advice
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 notifications.""" def shipped_message(order): return f"Order {str(order.id)} shipped to {order.city}"What Skylos leaves alone
"""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
- Runs with
--qualityon Python files. Looks at every f-string field that has no conversion flag yet. - Reports a field whose whole expression is
str(x),repr(x)orascii(x)with one plain argument, where the name resolves to the builtin (a localdef str, a parameter or an assignment namedstrturns the check off). - 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. - 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 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!scan 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'sRUF010in the project's ruff configuration also turns it off.