From 6704a70383965b63d5b9a1de17d0fb1c8564c32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Th=C3=A9nault?= Date: Thu, 15 Jan 2009 08:53:52 +0100 Subject: [PATCH] fix #6954, patch contributed by Mads Kiilerich --- checkers/utils.py | 3 +++ .../func_noerror_defined_and_used_on_same_line_py25.py | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/input/func_noerror_defined_and_used_on_same_line_py25.py diff --git a/checkers/utils.py b/checkers/utils.py index 575a71576..036a4cd7c 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -102,6 +102,9 @@ def is_defined_before(var_node, comp_node_types=COMP_NODE_TYPES): for ass_node in _node.assign.nodes_of_class(astng.AssName): if ass_node.name == varname: return True + elif isinstance(_node, astng.With): + if _node.vars.name == varname: + return True elif isinstance(_node, (astng.Lambda, astng.Function)): if varname in flatten(_node.argnames): return True diff --git a/test/input/func_noerror_defined_and_used_on_same_line_py25.py b/test/input/func_noerror_defined_and_used_on_same_line_py25.py new file mode 100644 index 000000000..71f6a1be1 --- /dev/null +++ b/test/input/func_noerror_defined_and_used_on_same_line_py25.py @@ -0,0 +1,8 @@ +# pylint: disable-msg=C0321 +"""test http://www.logilab.org/ticket/6954""" + +from __future__ import with_statement + +__revision__ = None + +with file('f') as f: print f.read()