summaryrefslogtreecommitdiff
path: root/checkers/variables.py
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-09-18 16:54:11 +0300
committercpopa <devnull@localhost>2014-09-18 16:54:11 +0300
commitf01bff14710891ad28f351c608aa6a316eeb2372 (patch)
treecd36cf68084fc036b6f75f784a26cd78b98f053d /checkers/variables.py
parent0850110102941286ff838e1c8b18530c4fd17bc3 (diff)
downloadpylint-f01bff14710891ad28f351c608aa6a316eeb2372.tar.gz
Fix another false positives with 'undefined-variable', where the variable can be found as a class assignment and used in a function annotation. Closes issue #342.
Diffstat (limited to 'checkers/variables.py')
-rw-r--r--checkers/variables.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/checkers/variables.py b/checkers/variables.py
index 8bd05b3..d1b04e1 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -737,11 +737,28 @@ builtins. Remember that you should avoid to define new builtins when possible.'
base_scope_type == 'comprehension' and i == start_index-1):
# Detect if we are in a local class scope, as an assignment.
# For example, the following is fair game.
+ #
# class A:
# b = 1
# c = lambda b=b: b * b
- if not (isinstance(frame, astroid.Class) and
- name in frame.locals):
+ #
+ # class B:
+ # tp = 1
+ # def func(self, arg: tp):
+ # ...
+
+ in_annotation = (
+ PY3K and isinstance(frame, astroid.Function)
+ and node.statement() is frame and
+ (node in frame.args.annotations
+ or node is frame.args.varargannotation
+ or node is frame.args.kwargannotation))
+ if in_annotation:
+ frame_locals = frame.parent.scope().locals
+ else:
+ frame_locals = frame.locals
+ if not ((isinstance(frame, astroid.Class) or in_annotation)
+ and name in frame_locals):
continue
# the name has already been consumed, only check it's not a loop
# variable used outside the loop