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()