Skip to content

Commit 82c31e5

Browse files
committed
Revert adding the new checker.
1 parent 5b011e9 commit 82c31e5

File tree

10 files changed

+5
-34
lines changed

10 files changed

+5
-34
lines changed

doc/data/messages/n/nonlocal-defined-at-module-level/bad.py

-2
This file was deleted.

doc/data/messages/n/nonlocal-defined-at-module-level/good.py

-5
This file was deleted.

doc/user_guide/checkers/features.rst

-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ Basic checker Messages
101101
Emitted when format function is not called on str object. e.g doing
102102
print("value: {}").format(123) instead of print("value: {}".format(123)).
103103
This might not be what the user intended to do.
104-
:nonlocal-defined-at-module-level (E0120): *nonlocal name %s defined at module level*
105-
Emitted when a nonlocal variable is defined at module-level which is a
106-
SyntaxError
107104
:nonlocal-without-binding (E0117): *nonlocal name %s found without binding*
108105
Emitted when a nonlocal variable does not have an attached name somewhere in
109106
the parent scopes

doc/user_guide/messages/messages_overview.rst

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ All messages in the error category:
130130
error/non-iterator-returned
131131
error/nonexistent-operator
132132
error/nonlocal-and-global
133-
error/nonlocal-defined-at-module-level
134133
error/nonlocal-without-binding
135134
error/not-a-mapping
136135
error/not-an-iterable

doc/whatsnew/fragments/8735.other

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Fix a crash when a ``nonlocal`` is defined at module-level.
2-
Add a new checker ``nonlocal-defined-at-module-level`` when a ``nonlocal`` is defined at module-level.
32

43
Closes #8735

pylint/checkers/base/basic_error_checker.py

-16
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,6 @@ class BasicErrorChecker(_BasicChecker):
204204
"which results in an error since Python 3.6.",
205205
{"minversion": (3, 6)},
206206
),
207-
"E0120": (
208-
"nonlocal name %s defined at module level",
209-
"nonlocal-defined-at-module-level",
210-
"Emitted when a nonlocal variable is defined at module-level "
211-
"which is a SyntaxError",
212-
),
213207
}
214208

215209
def open(self) -> None:
@@ -402,15 +396,6 @@ def visit_unaryop(self, node: nodes.UnaryOp) -> None:
402396

403397
def _check_nonlocal_without_binding(self, node: nodes.Nonlocal, name: str) -> None:
404398
current_scope = node.scope()
405-
if isinstance(current_scope, nodes.Module):
406-
self.add_message(
407-
"nonlocal-defined-at-module-level",
408-
args=(name,),
409-
node=node,
410-
confidence=HIGH,
411-
)
412-
return
413-
414399
while current_scope.parent is not None:
415400
if not isinstance(current_scope, (nodes.ClassDef, nodes.FunctionDef)):
416401
self.add_message("nonlocal-without-binding", args=(name,), node=node)
@@ -432,7 +417,6 @@ def _check_nonlocal_without_binding(self, node: nodes.Nonlocal, name: str) -> No
432417
)
433418

434419
@utils.only_required_for_messages("nonlocal-without-binding")
435-
@utils.only_required_for_messages("nonlocal-defined-at-module-level")
436420
def visit_nonlocal(self, node: nodes.Nonlocal) -> None:
437421
for name in node.names:
438422
self._check_nonlocal_without_binding(node, name)

tests/functional/n/nonlocal_defined_at_module_level.py

-5
This file was deleted.

tests/functional/n/nonlocal_defined_at_module_level.txt

-1
This file was deleted.

tests/functional/n/nonlocal_without_binding.py

+4
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ def inner():
6969
myint += 1
7070

7171
return inner()
72+
73+
74+
nonlocal APPLE # [nonlocal-without-binding]
75+
APPLE = 42

tests/functional/n/nonlocal_without_binding.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ nonlocal-without-binding:29:8:29:18:func.other_func:nonlocal name b found withou
22
nonlocal-without-binding:35:8:35:18:func.other_func2:nonlocal name c found without binding:HIGH
33
nonlocal-without-binding:40:4:40:14:SomeClass:nonlocal name x found without binding:HIGH
44
nonlocal-without-binding:43:8:43:26:SomeClass.func:nonlocal name some_attr found without binding:HIGH
5+
nonlocal-without-binding:74:0:74:14::nonlocal name APPLE found without binding:HIGH

0 commit comments

Comments
 (0)