diff options
| author | Torsten Marek <tmarek@google.com> | 2013-11-05 22:50:45 -0800 |
|---|---|---|
| committer | Torsten Marek <tmarek@google.com> | 2013-11-05 22:50:45 -0800 |
| commit | 07fb78c5ffe1edffb362689a809d909039d1e70b (patch) | |
| tree | 424d1973468b63c030b08a2833ac87416d804bde | |
| parent | 255208c56bc3e9f1cb2cfc2abc78cbabb5cda971 (diff) | |
| download | pylint-07fb78c5ffe1edffb362689a809d909039d1e70b.tar.gz | |
Fix a potential crash in the redefine-in-handler warning if the
redefined name is a nested getattr node.
| -rw-r--r-- | ChangeLog | 3 | ||||
| -rw-r--r-- | checkers/utils.py | 2 | ||||
| -rw-r--r-- | test/input/func_w0623_py_30.py | 3 | ||||
| -rw-r--r-- | test/messages/func_w0623_py_30.txt | 7 |
4 files changed, 10 insertions, 5 deletions
@@ -5,6 +5,9 @@ ChangeLog for Pylint * Avoid false used-before-assignment for except handler defined identifier used on the same line (#111) + * Fix a potential crash in the redefine-in-handler warning + if the redefined name is a nested getattr node. + * Add a new option for the multi-statement warning to allow single-line if statements. diff --git a/checkers/utils.py b/checkers/utils.py index a064404..72a9733 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -60,7 +60,7 @@ def clobber_in_except(node): (False, None) otherwise. """ if isinstance(node, astroid.AssAttr): - return (True, (node.attrname, 'object %r' % (node.expr.name,))) + return (True, (node.attrname, 'object %r' % (node.expr.as_string(),))) elif isinstance(node, astroid.AssName): name = node.name if is_builtin(name): diff --git a/test/input/func_w0623_py_30.py b/test/input/func_w0623_py_30.py index 7c489cc..9bccbc6 100644 --- a/test/input/func_w0623_py_30.py +++ b/test/input/func_w0623_py_30.py @@ -44,6 +44,8 @@ try: pass except KeyError, exceptions.RuntimeError: # W0623 pass +except KeyError, exceptions.RuntimeError.args: # W0623 + pass except KeyError, OSError: # W0623 pass except KeyError, MyOtherError: # W0623 @@ -63,4 +65,3 @@ except IOError, exc5: # this is fine print exc5 except MyOtherError, exc5: # this is fine print exc5 - diff --git a/test/messages/func_w0623_py_30.txt b/test/messages/func_w0623_py_30.txt index b764def..a2923f1 100644 --- a/test/messages/func_w0623_py_30.txt +++ b/test/messages/func_w0623_py_30.txt @@ -1,11 +1,12 @@ C: 28:some_function: Invalid variable name "FOO" C: 41: Invalid constant name "exc3" -C: 55: Invalid variable name "OOPS" +C: 57: Invalid variable name "OOPS" W: 18:some_function: Redefining name 'RuntimeError' from object 'exceptions' in exception handler W: 20:some_function: Redefining name 'OSError' from builtins in exception handler W: 20:some_function: Unused variable 'OSError' W: 22:some_function: Redefining name 'MyError' from outer scope (line 7) in exception handler W: 22:some_function: Unused variable 'MyError' W: 45: Redefining name 'RuntimeError' from object 'exceptions' in exception handler -W: 47: Redefining name 'OSError' from builtins in exception handler -W: 49: Redefining name 'MyOtherError' from outer scope (line 36) in exception handler +W: 47: Redefining name 'args' from object 'exceptions.RuntimeError' in exception handler +W: 49: Redefining name 'OSError' from builtins in exception handler +W: 51: Redefining name 'MyOtherError' from outer scope (line 36) in exception handler |
