diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-11-21 09:59:39 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-11-21 09:59:39 +0100 |
commit | 5c0c809051b851345e6e34b5c67f639bbf64b624 (patch) | |
tree | 8d9a16c32b82c3a9d71aeb1f5664bf5c8eae6849 | |
parent | 9b194e94d711929181aaa04c6ec27b4578f56017 (diff) | |
download | pylint-5c0c809051b851345e6e34b5c67f639bbf64b624.tar.gz |
fix false used-before-assignment for except handler defined identifier used on the same line (closes issue #111)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | checkers/utils.py | 5 | ||||
-rw-r--r-- | test/input/func_noerror_used_before_assignment.py | 5 |
3 files changed, 14 insertions, 1 deletions
@@ -2,9 +2,12 @@ ChangeLog for Pylint ==================== -- + * Avoid false used-before-assignment for except handler defined + identifier used on the same line (#111) + * Add 'bad-context-manager' error, checking that '__exit__' special method accepts the right number of arguments. - + * Run pylint as a python module 'python -m pylint' (anatoly techtonik) * Check for non-exception classes inside an except clause diff --git a/checkers/utils.py b/checkers/utils.py index 5e028f2..a064404 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -162,6 +162,11 @@ def is_defined_before(var_node): if getattr(_node, 'name', None) == varname: return True break + elif isinstance(_node, astroid.ExceptHandler): + if isinstance(_node.name, astroid.AssName): + ass_node=_node.name + if ass_node.name == varname: + return True _node = _node.parent # possibly multiple statements on the same line using semi colon separator stmt = var_node.statement() diff --git a/test/input/func_noerror_used_before_assignment.py b/test/input/func_noerror_used_before_assignment.py new file mode 100644 index 0000000..6ba0b88 --- /dev/null +++ b/test/input/func_noerror_used_before_assignment.py @@ -0,0 +1,5 @@ +# pylint: disable = line-too-long, multiple-statements, missing-module-attribute +"""https://bitbucket.org/logilab/pylint/issue/111/false-positive-used-before-assignment-with""" + +try: raise IOError(1, "a") +except IOError, err: print err |