diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-01-11 20:39:13 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-01-11 20:39:13 +0200 |
commit | 796e9d7a23c46ad6afbe0328e922ea2fe4925617 (patch) | |
tree | 6b28eeca20f98c18552002e99b89de771ca51bd4 /checkers/variables.py | |
parent | ee223a505ea9d2a71e9868c4b391c865008d45f5 (diff) | |
parent | 3a48d6623f43ef174dd13dab976e6564ab267654 (diff) | |
download | pylint-796e9d7a23c46ad6afbe0328e922ea2fe4925617.tar.gz |
Merged default into nonlocal
Diffstat (limited to 'checkers/variables.py')
-rw-r--r-- | checkers/variables.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 90b7fe7..4ad82c4 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -507,6 +507,31 @@ builtins. Remember that you should avoid to define new builtins when possible.' # defined in global or builtin scope 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 if (maybee0601 and stmt.fromlineno <= defstmt.fromlineno and not is_defined_before(node) |