From da1da56853380a5a387ad287f4398402b14ef123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rogalski?= Date: Wed, 4 Jan 2017 10:26:49 +0100 Subject: Fix not-used-before-assignment false positive (#1266) --- pylint/checkers/variables.py | 5 +++-- pylint/test/functional/used_before_assignment_issue1081.py | 10 +++++++++- 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) -- cgit v1.2.1