diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index b2898cbc..c60ecd49 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -301,6 +301,13 @@ class NameFinder(object): types += self._remove_statements(typ, name) elif isinstance(typ, pr.Import): types += imports.ImportWrapper(self._evaluator, name).follow() + elif isinstance(typ, pr.TryStmt): + # TODO an exception can also be a tuple. Check for those. + # TODO check for types that are not classes and add it to + # the static analysis report. + exceptions = evaluator.eval_element(name.prev_sibling().prev_sibling()) + types = list(chain.from_iterable( + evaluator.execute(t) for t in exceptions)) else: if typ.isinstance(er.Function) and resolve_decorator: typ = typ.get_decorated_func() @@ -333,20 +340,6 @@ class NameFinder(object): types += evaluator.eval_statement(stmt, seek_name=name) - # check for `except X as y` usages, because y needs to be instantiated. - p = stmt.parent - # TODO this looks really hacky, improve parser representation! - if isinstance(p, pr.Flow) and p.command == 'except' and p.inputs: - as_names = p.inputs[0].as_names - try: - if as_names[0] == name: - # TODO check for types that are not classes and add it to - # the static analysis report. - types = list(chain.from_iterable( - evaluator.execute(t) for t in types)) - except IndexError: - pass - if check_instance is not None: # class renames types = [er.get_instance_el(evaluator, check_instance, a, True) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 746a326c..af913cb6 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -275,6 +275,8 @@ class Name(Leaf): return self.start_pos < stmt.children[2].start_pos elif isinstance(stmt, Param): return self == stmt.get_name() + elif isinstance(stmt, TryStmt): + return self.prev_sibling() == 'as' else: return isinstance(stmt, (ExprStmt, Import, CompFor)) \ and self in stmt.get_defined_names()