diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 8262fa3a..8c209cc6 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -391,9 +391,9 @@ class BaseDefinition(object): if isinstance(self._definition, compiled.CompiledObject): non_flow = self._definition.parent else: - scope = self._definition.get_parent_scope() + scope = self._definition.get_definition().get_parent_scope() non_flow = scope.get_parent_until(pr.Flow, reverse=True) - return Definition(self._evaluator, non_flow) + return Definition(self._evaluator, non_flow.name.names[-1]) def __repr__(self): return "<%s %s>" % (type(self).__name__, self.description) @@ -565,7 +565,7 @@ class Completion(BaseDefinition): it's just PITA-slow. """ defs = self._follow_statements_imports() - return [Definition(self._evaluator, d) for d in defs] + return [Definition(self._evaluator, d.name.names[-1]) for d in defs] class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): @@ -760,7 +760,7 @@ class CallSignature(Definition): for i, param in enumerate(self.params): if self._key_name == param.name: return i - if self.params and self.params[-1]._definition.stars == 2: + if self.params and self.params[-1]._definition.get_definition().stars == 2: return i else: return None @@ -769,7 +769,7 @@ class CallSignature(Definition): for i, param in enumerate(self.params): # *args case - if param._definition.stars == 1: + if param._definition.get_definition().stars == 1: return i return None return self._index diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 94265d48..a93ae8e3 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -267,12 +267,16 @@ class NameFinder(object): # 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 and p.inputs[0].as_names[0].names[-1] == 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)) + if isinstance(p, pr.Flow) and p.command == 'except' and p.inputs: + as_names = p.inputs[0].as_names + try: + if as_names[0].names[-1] == 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 diff --git a/jedi/evaluate/imports.py b/jedi/evaluate/imports.py index f3cc5d75..640a5746 100644 --- a/jedi/evaluate/imports.py +++ b/jedi/evaluate/imports.py @@ -196,7 +196,7 @@ class ImportWrapper(pr.Base): # goto only accepts Names or NameParts if is_goto and not rest: - scopes = [s.name for s in scopes] + scopes = [s.name.names[-1] for s in scopes] # follow the rest of the import (not FS -> classes, functions) if len(rest) > 1 or rest and self.is_like_search: diff --git a/test/test_api/test_api_classes.py b/test/test_api/test_api_classes.py index 1c89d9d2..404aa849 100644 --- a/test/test_api/test_api_classes.py +++ b/test/test_api/test_api_classes.py @@ -170,8 +170,8 @@ class TestParent(TestCase): parent = self._parent('''\ def spam(): pass''', 1, len('def spam')) - assert parent.name == 'spam' - assert parent.parent().type == 'module' + assert parent.name == '' + assert parent.type == 'module' def test_parent_on_completion(self): parent = Script(dedent('''\