diff --git a/jedi/evaluate/filters.py b/jedi/evaluate/filters.py index 07878632..a18fc7ce 100644 --- a/jedi/evaluate/filters.py +++ b/jedi/evaluate/filters.py @@ -4,6 +4,8 @@ are needed for name resolution. """ from abc import abstractmethod +from jedi.parser.tree import search_ancestor + def filter_scope_names(names, scope, until_position=None, name=None): return names @@ -48,11 +50,15 @@ class ParserTreeFilter(AbstractFilter): class FunctionExecutionFilter(ParserTreeFilter): - def __init__(self, parser_scope, executed_function): + def __init__(self, parser_scope, executed_function, param_by_name): super(FunctionExecutionFilter, self).__init__(parser_scope) self._executed_function = executed_function + self._param_by_name = param_by_name def _filter(self, names, until_position): - result = super(FunctionExecutionFilter, self)._filter(names, until_position) + names = super(FunctionExecutionFilter, self)._filter(names, until_position) - return [self._executed_function.name_for_position(name.start_pos) for name in result] + names = [self._executed_function.name_for_position(name.start_pos) for name in names] + names = [self._param_by_name(str(name)) if search_ancestor(name, 'param') else name + for name in names] + return names diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 48116e70..a30ad526 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -679,6 +679,7 @@ class FunctionExecution(Executed): child.parent = self self.children = funcdef.children self.names_dict = funcdef.names_dict + self._copied_funcdef = funcdef @memoize_default(default=set()) @recursion.execution_recursion_decorator @@ -777,7 +778,8 @@ class FunctionExecution(Executed): del evaluator.predefined_if_name_dict_dict[for_stmt] def get_filters(self, search_global): - yield FunctionExecutionFilter(self._original_function, self.base.base_func) + yield FunctionExecutionFilter(self._original_function, + self._copied_funcdef, self.param_by_name) @memoize_default(default=NO_DEFAULT) def _get_params(self): diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index cd8f530e..bc763111 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -58,13 +58,10 @@ def search_ancestor(node, node_type_or_types): if not isinstance(node_type_or_types, (list, tuple)): node_type_or_types = (node_type_or_types,) - node = node.parent - while node.type not in node_type_or_types: - try: - node = node.parent - except AttributeError: - return None - return node + while True: + node = node.parent + if node is None or node.type in node_type_or_types: + return node class PositionModifier(object):