forked from VimPlug/jedi
except can also catch multiple exceptions in one statement
This commit is contained in:
@@ -73,14 +73,24 @@ def add(evaluator, name, jedi_obj, typ=Error):
|
|||||||
|
|
||||||
|
|
||||||
def _check_for_exception_catch(evaluator, jedi_obj, exception):
|
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):
|
def check_try_for_except(obj):
|
||||||
while obj.next is not None:
|
while obj.next is not None:
|
||||||
obj = obj.next
|
obj = obj.next
|
||||||
for i in obj.inputs:
|
for i in obj.inputs:
|
||||||
except_classes = evaluator.eval_statement(i)
|
except_classes = evaluator.eval_statement(i)
|
||||||
for cls in except_classes:
|
for cls in except_classes:
|
||||||
if isinstance(cls, CompiledObject) and cls.obj == exception:
|
from jedi.evaluate import iterable
|
||||||
return True
|
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
|
return False
|
||||||
|
|
||||||
while jedi_obj is not None and not jedi_obj.isinstance(pr.Function, pr.Class):
|
while jedi_obj is not None and not jedi_obj.isinstance(pr.Function, pr.Class):
|
||||||
|
|||||||
@@ -21,6 +21,19 @@ try:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# multi except
|
||||||
|
# -----------------
|
||||||
|
try:
|
||||||
|
str.not_existing
|
||||||
|
except (TypeError, AttributeError): pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
str.not_existing
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
except (NotImplementedError, AttributeError): pass
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# detailed except
|
# detailed except
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user