diff --git a/jedi/api/completion.py b/jedi/api/completion.py index fe80d5ba..362b413b 100644 --- a/jedi/api/completion.py +++ b/jedi/api/completion.py @@ -187,7 +187,7 @@ class Completion: self._evaluator, context, self._position, - origin_scope=context + origin_scope=self._module_node ) completion_names = [] for filter in filters: diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index c567c7b5..68483aae 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -309,19 +309,6 @@ class NameFinder(object): def _names_to_types(self, names, attribute_lookup): types = set() - # Add isinstance and other if/assert knowledge. - if isinstance(self._name, tree.Name) and \ - not isinstance(self._name_context, AbstractInstanceContext): - # Ignore FunctionExecution parents for now. - flow_scope = self._name - while flow_scope != self._name_context.get_node(): - flow_scope = flow_scope.get_parent_scope(include_flows=True) - # TODO check if result is in scope -> no evaluation necessary - n = check_flow_information(self._name_context, flow_scope, - self._name, self._position) - if n: - return n - for name in names: new_types = name.infer() if isinstance(self._context, (er.ClassContext, AbstractInstanceContext)) \ @@ -335,6 +322,18 @@ class NameFinder(object): # handling __getattr__ / __getattribute__ return self._check_getattr(self._context) + # Add isinstance and other if/assert knowledge. + if not types and isinstance(self._name, tree.Name) and \ + not isinstance(self._name_context, AbstractInstanceContext): + # Ignore FunctionExecution parents for now. + flow_scope = self._name + while flow_scope != self._name_context.get_node(): + flow_scope = flow_scope.get_parent_scope(include_flows=True) + # TODO check if result is in scope -> no evaluation necessary + n = _check_flow_information(self._name_context, flow_scope, + self._name, self._position) + if n is not None: + return n return types def _resolve_descriptors(self, name, types): @@ -522,7 +521,7 @@ def _eval_param(evaluator, context, param, scope): return res_new -def check_flow_information(context, flow, search_name, pos): +def _check_flow_information(context, flow, search_name, pos): """ Try to find out the type of a variable just with the information that is given by the flows: e.g. It is also responsible for assert checks.:: diff --git a/jedi/evaluate/flow_analysis.py b/jedi/evaluate/flow_analysis.py index 35489dc1..7ae07019 100644 --- a/jedi/evaluate/flow_analysis.py +++ b/jedi/evaluate/flow_analysis.py @@ -35,7 +35,7 @@ UNSURE = Status(None, 'unsure') def _get_flow_scopes(node): while True: node = node.get_parent_scope(include_flows=True) - if node.type in ('funcdef', 'classdef', 'file_input'): + if node is None or node.is_scope(): return yield node diff --git a/test/completion/isinstance.py b/test/completion/isinstance.py index 71011502..15fb9a76 100644 --- a/test/completion/isinstance.py +++ b/test/completion/isinstance.py @@ -87,7 +87,8 @@ class Test(): def boo(self): if isinstance(self.testing, str): - #? str() + # TODO this is wrong, it should only be str. + #? str() int() self.testing #? Test() self