Skip to content

prefer-fstring-over-concat

Prefer f-strings for short human-readable interpolation when they make the result clearer.

Why

For prose-like strings, f-strings keep interpolated values and surrounding text visible together.

Fix

Replace the interpolation with one f-string. Preserve an explicit str(value) conversion as {value!s} and repr(value) as {value!r} when those conversion semantics matter.

Examples

Before — flagged Known string is joined to literals
src/render.py
def greeting(name: str) -> str:
return "Hello, " + name + "!"
After — preferred Interpolation uses an f-string
src/render.py
def greeting(name: str) -> str:
return f"Hello, {name}!"