Skip to content

Commit c3820a9

Browse files
committed
Add message args, confidence and a test case for nonlocal that is not a parameter
1 parent fae605d commit c3820a9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

pylint/checkers/base/basic_error_checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,12 @@ def _check_nonlocal_and_parameter(self, node: nodes.FunctionDef) -> None:
339339
for body_node in node.nodes_of_class(nodes.Nonlocal):
340340
for non_local_name in body_node.names:
341341
if non_local_name in node_arg_names:
342-
self.add_message("name-is-parameter-and-nonlocal", node=body_node)
342+
self.add_message(
343+
"name-is-parameter-and-nonlocal",
344+
args=(non_local_name,),
345+
node=body_node,
346+
confidence=HIGH,
347+
)
343348

344349
def _check_nonlocal_and_global(self, node: nodes.FunctionDef) -> None:
345350
"""Check that a name is both nonlocal and global."""

tests/functional/n/name/name_is_parameter_and_nonlocal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33

44
def tomato(is_tasty: bool = True):
5+
nonlocal color
56
nonlocal is_tasty # [name-is-parameter-and-nonlocal]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
name-is-parameter-and-nonlocal:5:4:5:21:tomato:Name %r is parameter and nonlocal:UNDEFINED
1+
name-is-parameter-and-nonlocal:6:4:6:21:tomato:Name 'is_tasty' is parameter and nonlocal:HIGH

0 commit comments

Comments
 (0)