diff options
-rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/checkers/refactoring/recommendation_checker.py | 4 | ||||
-rw-r--r-- | tests/functional/c/consider/consider_using_f_string.py | 8 |
4 files changed, 16 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 34da2a803..4f4164cfa 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -546,3 +546,5 @@ contributors: * Jeroen Seegers (jeroenseegers): contributor - Fixed `toml` dependency issue + +* Tim Martin: contributor @@ -58,6 +58,10 @@ Release date: TBA Closes #3614 +* Fixed crash in ``consider-using-f-string`` if ``format`` is not called + + Closes #5058 + * Fix crash with ``AssignAttr`` in ``if TYPE_CHECKING`` blocks. Closes #5111 diff --git a/pylint/checkers/refactoring/recommendation_checker.py b/pylint/checkers/refactoring/recommendation_checker.py index 81a7dd7b1..3bccd5fcb 100644 --- a/pylint/checkers/refactoring/recommendation_checker.py +++ b/pylint/checkers/refactoring/recommendation_checker.py @@ -341,8 +341,8 @@ class RecommendationChecker(checkers.BaseChecker): isinstance(node.parent, nodes.Attribute) and node.parent.attrname == "format" ): - # Allow assigning .format to a variable - if isinstance(node.parent.parent, nodes.Assign): + # Don't warn on referencing / assigning .format without calling it + if not isinstance(node.parent.parent, nodes.Call): return if node.parent.parent.args: diff --git a/tests/functional/c/consider/consider_using_f_string.py b/tests/functional/c/consider/consider_using_f_string.py index 1d5400d5a..f6801989e 100644 --- a/tests/functional/c/consider/consider_using_f_string.py +++ b/tests/functional/c/consider/consider_using_f_string.py @@ -116,3 +116,11 @@ def assignment_bad(): h = "String %s" % (PARAM_1) # [consider-using-f-string] i = "String %s %s" % (PARAM_1, PARAM_2) # [consider-using-f-string] j = "String %s" % (PARAM_LIST_SINGLE) # [consider-using-f-string] + + +def regression_tests(): + # Referencing .format in a kwarg should not be warned + def wrap_print(value): + print(value) + + wrap_print(value="{}".format) |