Simplify f-string Formatting
Documentation Index
Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
Use this file to discover all available pages before exploring further.
Sourcery refactoring id: simplify-fstring-formatting
Section titled “Sourcery refactoring id: simplify-fstring-formatting”Description
Section titled “Description”Simplify the formatting of replacements within an f-string.
Before
Section titled “Before”name = "Tom"celebration = "hurrah"f"{name} is {5} years old, {f'{celebration.upper()}'}"name = "Tom"celebration = "hurrah"f"{name} is 5 years old, {celebration.upper()}"Explanation
Section titled “Explanation”This refactoring simplifies f-string:
- Inline constants directly into the f-strings
- Remove unnecessary nested f-strings if they are not needed