From 393833059a67d4d5838f6924f90c3a9a73d0e1eb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 23 Jun 2014 13:01:12 +0200 Subject: [PATCH] fixed inheritance for exception checks --- jedi/evaluate/analysis.py | 6 +++++- test/static_analysis/try_except.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/analysis.py b/jedi/evaluate/analysis.py index 368ef85f..9ad52387 100644 --- a/jedi/evaluate/analysis.py +++ b/jedi/evaluate/analysis.py @@ -85,7 +85,10 @@ def add(evaluator, name, jedi_obj, message=None, typ=Error, payload=None): def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None): """Returns True if the exception was catched.""" def check_match(cls): - return isinstance(cls, CompiledObject) and cls.obj == exception + try: + return isinstance(cls, CompiledObject) and issubclass(exception, cls.obj) + except TypeError: + return False def check_try_for_except(obj): while obj.next is not None: @@ -94,6 +97,7 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None): # No import implies a `except:` catch, which catches # everything. return True + for i in obj.inputs: except_classes = evaluator.eval_statement(i) for cls in except_classes: diff --git a/test/static_analysis/try_except.py b/test/static_analysis/try_except.py index 48c56d53..e6543280 100644 --- a/test/static_analysis/try_except.py +++ b/test/static_analysis/try_except.py @@ -61,6 +61,11 @@ except Undefined: # inheritance # ----------------- +try: + undefined +except Exception: + pass + # should catch everything try: undefined