1
0
forked from VimPlug/jedi

fixed some evil bugs in the import mechanism and even worse: In helpers.fast_parent_copy.

This commit is contained in:
David Halter
2012-10-22 17:22:44 +02:00
parent 99739754ef
commit 197c2f642b
7 changed files with 26 additions and 19 deletions

View File

@@ -90,7 +90,7 @@ class Parser(CachedModule):
name = name.rpartition('.')[0] # cut file type (normally .so) name = name.rpartition('.')[0] # cut file type (normally .so)
super(Parser, self).__init__(path=path, name=name) super(Parser, self).__init__(path=path, name=name)
self.sys_path = sys_path self.sys_path = list(sys_path)
self._module = None self._module = None
@property @property

View File

@@ -589,7 +589,7 @@ class Execution(Executable):
for param in self.base.params[start_offset:]: for param in self.base.params[start_offset:]:
# The value and key can both be null. There, the defaults apply. # The value and key can both be null. There, the defaults apply.
# args / kwargs will just be empty arrays / dicts, respectively. # args / kwargs will just be empty arrays / dicts, respectively.
# Wrong value count is just ignored. If you try to test cases which # Wrong value count is just ignored. If you try to test cases that
# are not allowed in Python, Jedi will maybe not show any # are not allowed in Python, Jedi will maybe not show any
# completions. # completions.
key, value = next(var_arg_iterator, (None, None)) key, value = next(var_arg_iterator, (None, None))

View File

@@ -58,7 +58,7 @@ class RecursionDecorator(object):
result = [] result = []
n = self.current n = self.current
while n: while n:
result.append(n.stmt) result.insert(0, n.stmt)
n = n.parent n = n.parent
return result return result
@@ -157,19 +157,26 @@ def fast_parent_copy(obj):
continue continue
if isinstance(value, list): if isinstance(value, list):
new_obj.__dict__[key] = list_rec(value) new_obj.__dict__[key] = list_rec(value)
elif isinstance(value, parsing.Simple): elif isinstance(value, (parsing.Simple, parsing.Call)):
new_obj.__dict__[key] = recursion(value) new_obj.__dict__[key] = recursion(value)
if obj.parent is not None: # replace parent (first try _parent and then parent)
if hasattr(obj, '_parent') and obj._parent is not None:
try:
new_obj._parent = weakref.ref(new_elements[obj._parent()])
except KeyError:
pass
elif obj.parent is not None:
try: try:
new_obj.parent = weakref.ref(new_elements[obj.parent()]) new_obj.parent = weakref.ref(new_elements[obj.parent()])
except KeyError: except KeyError:
pass pass
if hasattr(obj, 'parent_stmt') and obj.parent_stmt is not None: # replace parent_stmt
if hasattr(obj, '_parent_stmt') and obj._parent_stmt is not None:
p = obj.parent_stmt() p = obj.parent_stmt()
try: try:
new_obj.parent_stmt = weakref.ref(new_elements[p]) new_obj._parent_stmt = weakref.ref(new_elements[p])
except KeyError: except KeyError:
pass pass

View File

@@ -200,10 +200,10 @@ class ImportPath(object):
return i return i
if self.file_path: if self.file_path:
sys_path_mod = self.sys_path_with_modifications() sys_path_mod = list(self.sys_path_with_modifications())
sys_path_mod.insert(0, self.file_path) sys_path_mod.insert(0, self.file_path)
else: else:
sys_path_mod = builtin.module_find_path sys_path_mod = list(builtin.module_find_path)
current_namespace = None current_namespace = None
# now execute those paths # now execute those paths
@@ -218,7 +218,7 @@ class ImportPath(object):
raise ModuleNotFound( raise ModuleNotFound(
'The module you searched has not been found') 'The module you searched has not been found')
sys_path_mod.pop(0) sys_path_mod.pop(0) # TODO why is this here?
path = current_namespace[1] path = current_namespace[1]
is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY

View File

@@ -234,7 +234,7 @@ def sys_path_with_modifications(module):
try: try:
possible_stmts = module.used_names['path'] possible_stmts = module.used_names['path']
except KeyError: except KeyError:
return list(builtin.module_find_path) return builtin.module_find_path
sys_path = list(builtin.module_find_path) # copy sys_path = list(builtin.module_find_path) # copy
for p in possible_stmts: for p in possible_stmts:

View File

@@ -687,8 +687,7 @@ class Statement(Simple):
if self._assignment_calls_calculated: if self._assignment_calls_calculated:
return self._assignment_calls return self._assignment_calls
self._assignment_details = [] self._assignment_details = []
result = Array(self.start_pos, Array.NOARRAY, self) top = result = Array(self.start_pos, Array.NOARRAY, self)
top = result
level = 0 level = 0
is_chain = False is_chain = False
close_brackets = False close_brackets = False

View File

@@ -13,8 +13,7 @@ import api
#api.set_debug_function(api.debug.print_to_stdout) #api.set_debug_function(api.debug.print_to_stdout)
class Base(unittest.TestCase):
class TestRegression(unittest.TestCase):
def get_def(self, src, pos): def get_def(self, src, pos):
script = api.Script(src, pos[0], pos[1], None) script = api.Script(src, pos[0], pos[1], None)
return script.get_definition() return script.get_definition()
@@ -31,6 +30,7 @@ class TestRegression(unittest.TestCase):
script = api.Script(src, pos[0], pos[1], '') script = api.Script(src, pos[0], pos[1], '')
return script.get_in_function_call() return script.get_in_function_call()
class TestRegression(Base):
def test_part_parser(self): def test_part_parser(self):
""" test the get_in_function_call speedups """ """ test the get_in_function_call speedups """
s = '\n' * 100 + 'abs(' s = '\n' * 100 + 'abs('
@@ -192,12 +192,13 @@ class TestRegression(unittest.TestCase):
assert len(api.Script(s, 1, 15, '/').get_definition()) == 1 assert len(api.Script(s, 1, 15, '/').get_definition()) == 1
assert len(api.Script(s, 1, 10, '/').get_definition()) == 1 assert len(api.Script(s, 1, 10, '/').get_definition()) == 1
class TestSpeed(unittest.TestCase): class TestSpeed(Base):
def test_os_path_join(self): def test_os_path_join(self):
""" named import - jedi-vim issue #8 """ """ named import - jedi-vim issue #8 """
s = "join" s = "from posixpath import join; join('', '')."
assert len(api.Script(s, 1, 15, '/').get_definition()) == 1 #api.set_debug_function(api.debug.print_to_stdout)
assert len(api.Script(s, 1, 10, '/').get_definition()) == 1 assert len(self.complete(s)) > 10 # is a str completion
#api.set_debug_function(None)
if __name__ == '__main__': if __name__ == '__main__':