1
0
forked from VimPlug/jedi

Actually remove check_first from deep_ast_copy.

This commit is contained in:
Dave Halter
2015-02-11 14:47:28 +01:00
parent 315c687048
commit a12f259a0f

View File

@@ -4,7 +4,7 @@ from itertools import chain
from jedi.parser import tree as pr from jedi.parser import tree as pr
def deep_ast_copy(obj, new_elements=None, check_first=False): def deep_ast_copy(obj, new_elements=None):
""" """
Much, much faster than copy.deepcopy, but just for Parser elements (Doesn't Much, much faster than copy.deepcopy, but just for Parser elements (Doesn't
copy parents). copy parents).
@@ -15,12 +15,10 @@ def deep_ast_copy(obj, new_elements=None, check_first=False):
if new_elements is None: if new_elements is None:
new_elements = {} new_elements = {}
def recursion(obj, check_first=False): def recursion(obj):
# If it's already in the cache, just return it. # If it's already in the cache, just return it.
try: try:
new_obj = new_elements[obj] return new_elements[obj]
if not check_first:
return new_obj
except KeyError: except KeyError:
# Actually copy and set attributes. # Actually copy and set attributes.
new_obj = copy.copy(obj) new_obj = copy.copy(obj)
@@ -48,8 +46,7 @@ def deep_ast_copy(obj, new_elements=None, check_first=False):
for key, value in items: for key, value in items:
if key == 'parent': if key == 'parent':
try: try:
if not check_first: setattr(new_obj, key, new_elements[value])
setattr(new_obj, key, new_elements[value])
except KeyError: except KeyError:
pass # The parent can be what it was before. pass # The parent can be what it was before.
elif key == 'position_modifier': elif key == 'position_modifier':
@@ -78,8 +75,7 @@ def deep_ast_copy(obj, new_elements=None, check_first=False):
if isinstance(array_obj, tuple): if isinstance(array_obj, tuple):
return tuple(copied_array) return tuple(copied_array)
return copied_array return copied_array
return recursion(obj)
return recursion(obj, check_first=check_first)
def call_of_name(name, cut_own_trailer=False): def call_of_name(name, cut_own_trailer=False):