Skip to content

Commit

Permalink
Fix not-used-before-assignment false positive (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogalski authored and PCManticore committed Jan 4, 2017
1 parent ea6c74a commit da1da56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pylint/checkers/variables.py
Expand Up @@ -901,8 +901,9 @@ def _is_variable_violation(node, name, defnode, stmt, defstmt,
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
Expand Down
10 changes: 9 additions & 1 deletion 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

Expand Down Expand Up @@ -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)

0 comments on commit da1da56

Please sign in to comment.