Skip to content

Commit 71ad672

Browse files
committed
Fix false positive for f-string-without-interpolation
1 parent f8f6ccd commit 71ad672

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
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):

tests/functional/f/f_string_without_interpolation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
print(f"some value {VALUE}")
77
print(f'pi: {math.pi:.3f}')
8+
print(t"{math.pi:.1f}")
89

910
print(f"ERROR") # [f-string-without-interpolation]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f-string-without-interpolation:9:6:9:14::Using an f-string that does not have any interpolated variables:UNDEFINED
1+
f-string-without-interpolation:10:6:10:14::Using an f-string that does not have any interpolated variables:UNDEFINED

0 commit comments

Comments
 (0)