summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorƁukasz Rogalski <rogalski.91@gmail.com>2017-01-04 10:26:49 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2017-01-04 11:26:49 +0200
commitda1da56853380a5a387ad287f4398402b14ef123 (patch)
tree2e06d8156c2fbf332ff9bb39d7334cfe2350eb11
parentea6c74adce6613d543cb3689f39450d4a83166f5 (diff)
downloadpylint-git-da1da56853380a5a387ad287f4398402b14ef123.tar.gz
Fix not-used-before-assignment false positive (#1266)
-rw-r--r--pylint/checkers/variables.py5
-rw-r--r--pylint/test/functional/used_before_assignment_issue1081.py10
2 files changed, 12 insertions, 3 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 0455eb382..87b3afc0b 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -901,8 +901,9 @@ class VariablesChecker(BaseChecker):
else:
# we are in a local scope, check the name is not
# defined in global or builtin scope
- # skip this lookup if name is assigned later in given scope
- if not _assigned_locally(node) and defframe.root().lookup(name)[1]:
+ # skip this lookup if name is assigned later in function scope
+ forbid_lookup = isinstance(frame, astroid.FunctionDef) and _assigned_locally(node)
+ if not forbid_lookup and defframe.root().lookup(name)[1]:
maybee0601 = False
else:
# check if we have a nonlocal
diff --git a/pylint/test/functional/used_before_assignment_issue1081.py b/pylint/test/functional/used_before_assignment_issue1081.py
index 3b1a82511..c2e0d88b5 100644
--- a/pylint/test/functional/used_before_assignment_issue1081.py
+++ b/pylint/test/functional/used_before_assignment_issue1081.py
@@ -1,4 +1,4 @@
-# pylint: disable=missing-docstring,invalid-name
+# pylint: disable=missing-docstring,invalid-name,too-few-public-methods
x = 24
@@ -30,3 +30,11 @@ def not_used_before_assignment_2(a):
x = 3 # [redefined-outer-name]
if x == a:
pass
+
+
+def func(something):
+ return something ** 3
+
+
+class FalsePositive(object):
+ x = func(x)