1
0
forked from VimPlug/jedi

Name parents are now Calls (once their statements have generated the Calls).

This makes the goto function more powerful. Also fixes an issue with the deep_ast_copy, that I tried to fix previously, but failed, because I hadn't tested it.
This commit is contained in:
Dave Halter
2014-09-06 12:18:40 +02:00
parent 5a3ee02399
commit 2e7e2f0a29
2 changed files with 8 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
import copy import copy
from itertools import chain from itertools import chain
from jedi import common
from jedi.parser import representation as pr from jedi.parser import representation as pr
from jedi import debug from jedi import debug
@@ -12,7 +11,7 @@ def deep_ast_copy(obj, new_elements_default=None):
copy parents). copy parents).
""" """
def sort_stmt(key_value): def sort_stmt(key_value):
return key_value[0] in ('_expression_list', '_assignment_details') return key_value[0] not in ('_expression_list', '_assignment_details')
new_elements = new_elements_default or {} new_elements = new_elements_default or {}
accept = (pr.Simple, pr.NamePart, pr.KeywordStatement) accept = (pr.Simple, pr.NamePart, pr.KeywordStatement)
@@ -38,11 +37,13 @@ def deep_ast_copy(obj, new_elements_default=None):
before = () before = ()
for cls in obj.__class__.__mro__: for cls in obj.__class__.__mro__:
with common.ignored(AttributeError): try:
if before == cls.__slots__: if before == cls.__slots__:
continue continue
before = cls.__slots__ before = cls.__slots__
items += [(n, getattr(obj, n)) for n in before] items += [(n, getattr(obj, n)) for n in before]
except AttributeError:
pass
if isinstance(obj, pr.Statement): if isinstance(obj, pr.Statement):
# We need to process something with priority for statements, # We need to process something with priority for statements,
@@ -60,8 +61,10 @@ def deep_ast_copy(obj, new_elements_default=None):
if key == 'parent' and '_parent' in items: if key == 'parent' and '_parent' in items:
# parent can be a property # parent can be a property
continue continue
with common.ignored(KeyError): try:
setattr(new_obj, key, new_elements[value]) setattr(new_obj, key, new_elements[value])
except KeyError:
pass
elif key in ['parent_function', 'use_as_parent', '_sub_module']: elif key in ['parent_function', 'use_as_parent', '_sub_module']:
continue continue
elif isinstance(value, (list, tuple)): elif isinstance(value, (list, tuple)):

View File

@@ -1323,6 +1323,7 @@ class Call(StatementElement):
def __init__(self, module, name, start_pos, end_pos, parent=None): def __init__(self, module, name, start_pos, end_pos, parent=None):
super(Call, self).__init__(module, start_pos, end_pos, parent) super(Call, self).__init__(module, start_pos, end_pos, parent)
name.parent = self
self.name = name self.name = name
def get_code(self): def get_code(self):