diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2014-01-09 11:13:46 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2014-01-09 11:13:46 +0200 |
commit | 9e0dfe50de779a4fdf4d2abe80587f541c7cb71c (patch) | |
tree | 40d2bedd608de6e84a6a2ae6282dca715dfc80fd | |
parent | c23e3e4689a189a9b9b9ca4f222b5fc184bc3e5a (diff) | |
parent | f02fb1f0f582ff8a66cd50e1a08bce5a507a3cdc (diff) | |
download | pylint-9e0dfe50de779a4fdf4d2abe80587f541c7cb71c.tar.gz |
Merged logilab/pylint into default
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | checkers/utils.py | 6 | ||||
-rw-r--r-- | test/input/func_with_used_before_assignment.py | 12 | ||||
-rw-r--r-- | test/messages/func_with_used_before_assignment.txt | 2 |
4 files changed, 23 insertions, 2 deletions
@@ -1,6 +1,11 @@ ChangeLog for Pylint ==================== +-- + * bitbucket #128: pylint doesn't crash when looking + for used-before-assignment in context manager + assignments. + 2013-12-22 -- 1.1.0 * Add new check for use of deprecated pragma directives "pylint:disable-msg" or "pylint:enable-msg" (I0022, deprecated-pragma) which was previously diff --git a/checkers/utils.py b/checkers/utils.py index 53b40a6..7387711 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -154,8 +154,10 @@ def is_defined_before(var_node): elif isinstance(_node, astroid.With): for expr, vars in _node.items: if expr.parent_of(var_node): - break - if vars and vars.name == varname: + break + if (vars and + isinstance(vars, astroid.AssName) and + vars.name == varname): return True elif isinstance(_node, (astroid.Lambda, astroid.Function)): if _node.args.is_argument(varname): diff --git a/test/input/func_with_used_before_assignment.py b/test/input/func_with_used_before_assignment.py new file mode 100644 index 0000000..c79815c --- /dev/null +++ b/test/input/func_with_used_before_assignment.py @@ -0,0 +1,12 @@ +''' +Regression test for +https://bitbucket.org/logilab/pylint/issue/128/attributeerror-when-parsing +''' +from __future__ import with_statement +__revision__ = 1 + +def do_nothing(): + """ empty """ + with open("") as ctx.obj: + context.do() + context = None diff --git a/test/messages/func_with_used_before_assignment.txt b/test/messages/func_with_used_before_assignment.txt new file mode 100644 index 0000000..dc6e386 --- /dev/null +++ b/test/messages/func_with_used_before_assignment.txt @@ -0,0 +1,2 @@ +E: 10:do_nothing: Undefined variable 'ctx'
+E: 11:do_nothing: Using variable 'context' before assignment
\ No newline at end of file |