Skip to content

Commit fc920b6

Browse files
[Backport maintenance/4.0.x] Fix false positive for f-string-without-interpolation with template strings when using format spec (#10717)
Fix false positive for `f-string-without-interpolation` with template strings when using format spec (#10716) (cherry picked from commit d2589f1) Co-authored-by: Zen Lee <53538590+zenlyj@users.noreply.github.com>
1 parent aeffe52 commit fc920b6

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix false positive for ``f-string-without-interpolation`` with template strings
2+
when using format spec.
3+
4+
Closes #10702

pylint/checkers/strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def visit_joinedstr(self, node: nodes.JoinedStr) -> None:
409409
self._check_interpolation(node)
410410

411411
def _check_interpolation(self, node: nodes.JoinedStr) -> None:
412-
if isinstance(node.parent, nodes.FormattedValue):
412+
if isinstance(node.parent, (nodes.TemplateStr, nodes.FormattedValue)):
413413
return
414414
for value in node.values:
415415
if isinstance(value, nodes.FormattedValue):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# pylint: disable=missing-module-docstring
2+
3+
PI = 3.14
4+
print(t"{PI:.1f}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.14

0 commit comments

Comments
 (0)