From 0a3bc34d6b0deef80a4b1a72e1c16231774b245c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 21 Jun 2016 18:39:02 +0200 Subject: [PATCH] Fix some more issues with the call_of_name function. --- jedi/evaluate/helpers.py | 8 +++++--- jedi/evaluate/representation.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index 7ef6668c..490992bf 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -84,18 +84,20 @@ def call_of_name(leaf, cut_own_trailer=False): # ignore it, It's not what we want anyway. Or document it better? """ trailer = leaf.parent - print(leaf) # The leaf may not be the last or first child, because there exist three # different trailers: `( x )`, `[ x ]` and `.x`. In the first two examples # we should not match anything more than x. if trailer.type != 'trailer' or leaf not in (trailer.children[0], trailer.children[-1]): return leaf - assert not cut_own_trailer # TODO remove power = trailer.parent index = power.children.index(trailer) power = deep_ast_copy(power) - power.children[index + 1:] = [] + if cut_own_trailer: + cut = index + else: + cut = index + 1 + power.children[cut:] = [] if power.type == 'error_node': transformed = tree.Node('power', power.children) diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 60148bfc..66d92463 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -537,6 +537,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)): if trailer: # Create a trailer and evaluate it. trailer = tree.Node('trailer', trailer) + # TODO WTF WHY IS THIS CHANGING PARENTS trailer.parent = dec dec_results = self._evaluator.eval_trailer(dec_results, trailer) @@ -632,7 +633,9 @@ class FunctionExecution(Executed): self._copy_dict = {} new_func = helpers.deep_ast_copy(base.base_func, new_elements=self._copy_dict) for child in new_func.children: - child.parent = self + if child.type not in ('operator', 'keyword'): + # Not all nodes are properly copied by deep_ast_copy. + child.parent = self self.children = new_func.children self.names_dict = new_func.names_dict