summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2014-01-03 19:22:35 +0200
committercpopa <devnull@localhost>2014-01-03 19:22:35 +0200
commit12a7edcc811c921875eb794e5e1e8985fe978c68 (patch)
treed1c055bcc0601391e99d28e6ede47bb75c24efe9
parente099a5685de2fd625de831d060d0b4a91ed4481d (diff)
downloadpylint-12a7edcc811c921875eb794e5e1e8985fe978c68.tar.gz
Fix bitbucket #126, don't crash when encountering an AssAttr node in is_defined_before.
-rw-r--r--ChangeLog5
-rw-r--r--checkers/utils.py6
-rw-r--r--test/input/func_with_e0601.py12
-rw-r--r--test/messages/func_with_e0601.txt2
4 files changed, 23 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index f5b7192..f24d7c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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..a193220 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
+ not isinstance(vars, astroid.AssAttr) 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_e0601.py b/test/input/func_with_e0601.py
new file mode 100644
index 0000000..c79815c
--- /dev/null
+++ b/test/input/func_with_e0601.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_e0601.txt b/test/messages/func_with_e0601.txt
new file mode 100644
index 0000000..dc6e386
--- /dev/null
+++ b/test/messages/func_with_e0601.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