From 743d064e6d7422c46dc0f80f582fc10c75b0adfe Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 7 Aug 2014 12:10:31 +0200 Subject: [PATCH] exception while using else as a scope --- jedi/evaluate/flow_analysis.py | 13 +++++++------ test/completion/flow_analysis.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/jedi/evaluate/flow_analysis.py b/jedi/evaluate/flow_analysis.py index 01c29529..3740b937 100644 --- a/jedi/evaluate/flow_analysis.py +++ b/jedi/evaluate/flow_analysis.py @@ -35,13 +35,14 @@ UNSURE = Status(None, 'unsure') def break_check(evaluator, base_scope, element_scope): reachable = REACHABLE if isinstance(element_scope, Flow): + check_scope = element_scope invert = False - if element_scope.command == 'else': - element_scope = element_scope.previous + if check_scope.command == 'else': + check_scope = check_scope.previous invert = True - if element_scope.command == 'if' and element_scope.inputs: - types = evaluator.eval_statement(element_scope.inputs[0]) + if check_scope.command == 'if' and check_scope.inputs: + types = evaluator.eval_statement(check_scope.inputs[0]) values = set(x.py__bool__() for x in types) if len(values) == 1: reachable = Status.lookup_table[values.pop()] @@ -51,9 +52,9 @@ def break_check(evaluator, base_scope, element_scope): return UNREACHABLE else: return UNSURE - elif element_scope.command == 'try': + elif check_scope.command in ('try', 'except', 'finally'): reachable = UNSURE - if base_scope != element_scope and base_scope != element_scope.parent: + if base_scope != element_scope and base_scope != check_scope.parent: return reachable & break_check(evaluator, base_scope, element_scope.parent) return reachable diff --git a/test/completion/flow_analysis.py b/test/completion/flow_analysis.py index 75f7b4e9..772b65b5 100644 --- a/test/completion/flow_analysis.py +++ b/test/completion/flow_analysis.py @@ -11,12 +11,12 @@ foo(1) # Exceptions are not analyzed. So check both if branches def try_except(x): try: - if 1.0: + if 0: return 1 else: return '' except AttributeError: return 1.0 -#? int() float() +#? float() str() try_except(1)