forked from VimPlug/jedi
except can also catch multiple exceptions in one statement
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user