From 315c6870488c2c7c52aaca31663610bf253caf52 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 11 Feb 2015 14:46:51 +0100 Subject: [PATCH] Remove the need for the check_first param in deep_ast_copy. --- jedi/evaluate/helpers.py | 5 +++-- jedi/evaluate/representation.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index b1f8f728..7f297baa 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -4,7 +4,7 @@ from itertools import chain from jedi.parser import tree as pr -def deep_ast_copy(obj, new_elements_default=None, check_first=False): +def deep_ast_copy(obj, new_elements=None, check_first=False): """ Much, much faster than copy.deepcopy, but just for Parser elements (Doesn't copy parents). @@ -12,7 +12,8 @@ def deep_ast_copy(obj, new_elements_default=None, check_first=False): def sort_stmt(key_value): return key_value[0] not in ('_expression_list', '_assignment_details') - new_elements = new_elements_default or {} + if new_elements is None: + new_elements = {} def recursion(obj, check_first=False): # If it's already in the cache, just return it. diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 5c265f9f..ffcf483a 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -569,10 +569,13 @@ class FunctionExecution(Executed): def __init__(self, evaluator, base, *args, **kwargs): super(FunctionExecution, self).__init__(evaluator, base, *args, **kwargs) - # for deep_ast_copy - func = base.base_func - self._copy_dict = {func: self, func.parent: func.parent} - helpers.deep_ast_copy(self.base.base_func, self._copy_dict, check_first=True) + self._copy_dict = {} + new_func = helpers.deep_ast_copy(base.base_func, self._copy_dict) + for child in new_func.children: + if isinstance(child, (pr.Name, pr.BaseNode)): + child.parent = self + self.children = new_func.children + self.names_dict = new_func.names_dict @memoize_default(default=()) @recursion.execution_recursion_decorator @@ -610,9 +613,9 @@ class FunctionExecution(Executed): return types def names_dicts(self, search_global): - self.children yield dict((k, [self._copy_dict[v] for v in values]) for k, values in self.base.names_dict.items()) + #yield self.names_dict # Replace with this! @memoize_default(default=NO_DEFAULT) def _get_params(self):