1
0
forked from VimPlug/jedi

except can also catch multiple exceptions in one statement

This commit is contained in:
Dave Halter
2014-05-12 18:46:17 +02:00
parent 7096a570bf
commit 00e43d4585
2 changed files with 25 additions and 2 deletions

View File

@@ -73,13 +73,23 @@ def add(evaluator, name, jedi_obj, typ=Error):
def _check_for_exception_catch(evaluator, jedi_obj, exception):
def check_match(cls):
return isinstance(cls, CompiledObject) and cls.obj == exception
def check_try_for_except(obj):
while obj.next is not None:
obj = obj.next
for i in obj.inputs:
except_classes = evaluator.eval_statement(i)
for cls in except_classes:
if isinstance(cls, CompiledObject) and cls.obj == exception:
from jedi.evaluate import iterable
if isinstance(cls, iterable.Array) and cls.type == 'tuple':
# multiple exceptions
for c in cls.values():
if check_match(c):
return True
else:
if check_match(cls):
return True
return False

View File

@@ -21,6 +21,19 @@ try:
except AttributeError:
pass
# -----------------
# multi except
# -----------------
try:
str.not_existing
except (TypeError, AttributeError): pass
try:
str.not_existing
except ImportError:
pass
except (NotImplementedError, AttributeError): pass
# -----------------
# detailed except
# -----------------