diff --git a/doc/whatsnew/fragments/10702.false_positive b/doc/whatsnew/fragments/10702.false_positive new file mode 100644 index 0000000000..301d691fae --- /dev/null +++ b/doc/whatsnew/fragments/10702.false_positive @@ -0,0 +1,4 @@ +Fix false positive for ``f-string-without-interpolation`` with template strings +when using format spec. + +Closes #10702 diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py index 0260798b46..644974b741 100644 --- a/pylint/checkers/strings.py +++ b/pylint/checkers/strings.py @@ -409,7 +409,7 @@ def visit_joinedstr(self, node: nodes.JoinedStr) -> None: self._check_interpolation(node) def _check_interpolation(self, node: nodes.JoinedStr) -> None: - if isinstance(node.parent, nodes.FormattedValue): + if isinstance(node.parent, (nodes.TemplateStr, nodes.FormattedValue)): return for value in node.values: if isinstance(value, nodes.FormattedValue): diff --git a/tests/functional/f/f_string_without_interpolation_py314.py b/tests/functional/f/f_string_without_interpolation_py314.py new file mode 100644 index 0000000000..7aa00a824d --- /dev/null +++ b/tests/functional/f/f_string_without_interpolation_py314.py @@ -0,0 +1,4 @@ +# pylint: disable=missing-module-docstring + +PI = 3.14 +print(t"{PI:.1f}") diff --git a/tests/functional/f/f_string_without_interpolation_py314.rc b/tests/functional/f/f_string_without_interpolation_py314.rc new file mode 100644 index 0000000000..a4a5d4fab5 --- /dev/null +++ b/tests/functional/f/f_string_without_interpolation_py314.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.14