[clang] [clang][Python] Use fstrings instead of string concatenations (PR #173861)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 29 20:51:31 PST 2025
Endilll wrote:
> I have noticed the code did use fstrings previously in a few locations, but string interpolation is generally a lesser cognitive load to read than the `str.format()` method which puts all the variables at the end. Personally I think it's easier to read the interpolated string with arguments in place.
When I'm looking at the changes you propose:
```diff
- return "<SourceLocation file %r, line %r, column %r>" % (
- filename,
- self.line,
- self.column,
- )
+ return f"<SourceLocation file {filename!r}, line {self.line!r}, column {self.column!r}>"
```
or
```diff
- return "<Diagnostic severity %r, location %r, spelling %r>" % (
- self.severity,
- self.location,
- self.spelling,
- )
+ return f"<Diagnostic severity {self.severity!r}, location {self.location!r}, spelling {self.spelling!r}>"
```
I'm sorry I fail to notice the reduction in cognitive load.
CC @DeinAlptraum if you think f-strings are an improvement, that's your chance to convince me.
https://github.com/llvm/llvm-project/pull/173861
More information about the cfe-commits
mailing list