diff options
author | tmarek <tmarek@google.com> | 2012-06-07 14:55:15 +0200 |
---|---|---|
committer | tmarek <tmarek@google.com> | 2012-06-07 14:55:15 +0200 |
commit | beea423285b3290d407945c348116622f0f7f9db (patch) | |
tree | caea4d2354d564b4582ac08411cf90b17ea3e936 /checkers/utils.py | |
parent | e55d63fc8e99f24395675993a520f90c4760d8d6 (diff) | |
download | pylint-beea423285b3290d407945c348116622f0f7f9db.tar.gz |
Closes #93591: Correctly emit W0623 on multiple assignment of unpackable exceptions
eg for code like
try:
...
except AnyException as (here, there):
...
Instead of warning about redefining tuple, recurse into the tuple and check all names.
Diffstat (limited to 'checkers/utils.py')
-rw-r--r-- | checkers/utils.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/checkers/utils.py b/checkers/utils.py index 2102bbb..f4fc4a8 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -27,9 +27,24 @@ BUILTINS_NAME = builtins.__name__ COMP_NODE_TYPES = astng.ListComp, astng.SetComp, astng.DictComp, astng.GenExpr + def is_inside_except(node): - """Returns true if node is directly inside an exception handler""" - return isinstance(node.parent, astng.ExceptHandler) + """Returns true if node is inside the name of an except handler.""" + current = node + while current and not isinstance(current.parent, astng.ExceptHandler): + current = current.parent + + return current and current is current.parent.name + + +def get_all_elements(node): + """Recursively returns all atoms in nested lists and tuples.""" + if isinstance(node, (astng.Tuple, astng.List)): + for child in node.elts: + for e in get_all_elements(child): + yield e + else: + yield node def clobber_in_except(node): @@ -41,7 +56,7 @@ def clobber_in_except(node): """ if isinstance(node, astng.AssAttr): return (True, (node.attrname, 'object %r' % (node.expr.name,))) - elif node is not None: + elif isinstance(node, astng.AssName): name = node.name if is_builtin(name): return (True, (name, 'builtins')) |