summaryrefslogtreecommitdiff
path: root/checkers/variables.py
diff options
context:
space:
mode:
Diffstat (limited to 'checkers/variables.py')
-rw-r--r--checkers/variables.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/checkers/variables.py b/checkers/variables.py
index 4ad82c4..6ab6927 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -508,30 +508,14 @@ builtins. Remember that you should avoid to define new builtins when possible.'
if defframe.root().lookup(name)[1]:
maybee0601 = False
else:
- # check if we have a nonlocal
- frame = node.frame()
- frame_parent = frame.parent
- if (isinstance(frame, astroid.Function) and
- isinstance(frame_parent, astroid.Function)):
- # detect that the name exists
- # in the upper level
- defined_higher = False
- for assign in frame_parent.get_children():
- if not isinstance(assign, astroid.Assign):
- continue
- for target in assign.targets:
- if (isinstance(target, astroid.AssName) and
- target.name == name):
- defined_higher = True
- break
- if defined_higher:
- break
- for child in frame.get_children():
- if not isinstance(child, astroid.Nonlocal):
- continue
- if name in child.names and defined_higher:
- maybee0601 = False
- break
+ # check if we have a nonlocal
+ if name in defframe.locals:
+ for child in defframe.get_children():
+ if not isinstance(child, astroid.Nonlocal):
+ continue
+ if name in child.names:
+ maybee0601 = False
+ break
if (maybee0601
and stmt.fromlineno <= defstmt.fromlineno
and not is_defined_before(node)