Skip to content
This repository
Browse code

fixed some evil bugs in the import mechanism and even worse: In helpe…

…rs.fast_parent_copy.
  • Loading branch information...
commit 197c2f642bd0177ffc0c62758b0229e0cca0ebce 1 parent 9973975
Dave Halter authored October 22, 2012
2  jedi/builtin.py
@@ -90,7 +90,7 @@ def __init__(self, path=None, name=None, sys_path=module_find_path):
90 90
             name = name.rpartition('.')[0]  # cut file type (normally .so)
91 91
         super(Parser, self).__init__(path=path, name=name)
92 92
 
93  
-        self.sys_path = sys_path
  93
+        self.sys_path = list(sys_path)
94 94
         self._module = None
95 95
 
96 96
     @property
2  jedi/evaluate.py
@@ -589,7 +589,7 @@ def gen_param_name_copy(param, keys=[], values=[], array_type=None):
589 589
         for param in self.base.params[start_offset:]:
590 590
             # The value and key can both be null. There, the defaults apply.
591 591
             # args / kwargs will just be empty arrays / dicts, respectively.
592  
-            # Wrong value count is just ignored. If you try to test cases which
  592
+            # Wrong value count is just ignored. If you try to test cases that
593 593
             # are not allowed in Python, Jedi will maybe not show any
594 594
             # completions.
595 595
             key, value = next(var_arg_iterator, (None, None))
17  jedi/helpers.py
@@ -58,7 +58,7 @@ def node_statements(self):
58 58
         result = []
59 59
         n = self.current
60 60
         while n:
61  
-            result.append(n.stmt)
  61
+            result.insert(0, n.stmt)
62 62
             n = n.parent
63 63
         return result
64 64
 
@@ -157,19 +157,26 @@ def recursion(obj):
157 157
                 continue
158 158
             if isinstance(value, list):
159 159
                 new_obj.__dict__[key] = list_rec(value)
160  
-            elif isinstance(value, parsing.Simple):
  160
+            elif isinstance(value, (parsing.Simple, parsing.Call)):
161 161
                 new_obj.__dict__[key] = recursion(value)
162 162
 
163  
-        if obj.parent is not None:
  163
+        # replace parent (first try _parent and then parent)
  164
+        if hasattr(obj, '_parent') and obj._parent is not None:
  165
+            try:
  166
+                new_obj._parent = weakref.ref(new_elements[obj._parent()])
  167
+            except KeyError:
  168
+                pass
  169
+        elif obj.parent is not None:
164 170
             try:
165 171
                 new_obj.parent = weakref.ref(new_elements[obj.parent()])
166 172
             except KeyError:
167 173
                 pass
168 174
 
169  
-        if hasattr(obj, 'parent_stmt') and obj.parent_stmt is not None:
  175
+        # replace parent_stmt
  176
+        if hasattr(obj, '_parent_stmt') and obj._parent_stmt is not None:
170 177
             p = obj.parent_stmt()
171 178
             try:
172  
-                new_obj.parent_stmt = weakref.ref(new_elements[p])
  179
+                new_obj._parent_stmt = weakref.ref(new_elements[p])
173 180
             except KeyError:
174 181
                 pass
175 182
 
6  jedi/imports.py
@@ -200,10 +200,10 @@ def follow_str(ns, string):
200 200
                 return i
201 201
 
202 202
         if self.file_path:
203  
-            sys_path_mod = self.sys_path_with_modifications()
  203
+            sys_path_mod = list(self.sys_path_with_modifications())
204 204
             sys_path_mod.insert(0, self.file_path)
205 205
         else:
206  
-            sys_path_mod = builtin.module_find_path
  206
+            sys_path_mod = list(builtin.module_find_path)
207 207
 
208 208
         current_namespace = None
209 209
         # now execute those paths
@@ -218,7 +218,7 @@ def follow_str(ns, string):
218 218
                     raise ModuleNotFound(
219 219
                             'The module you searched has not been found')
220 220
 
221  
-        sys_path_mod.pop(0)
  221
+        sys_path_mod.pop(0)  # TODO why is this here?
222 222
         path = current_namespace[1]
223 223
         is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY
224 224
 
2  jedi/modules.py
@@ -234,7 +234,7 @@ def check_module(module):
234 234
         try:
235 235
             possible_stmts = module.used_names['path']
236 236
         except KeyError:
237  
-            return list(builtin.module_find_path)
  237
+            return builtin.module_find_path
238 238
 
239 239
         sys_path = list(builtin.module_find_path)  # copy
240 240
         for p in possible_stmts:
3  jedi/parsing.py
@@ -687,8 +687,7 @@ def get_assignment_calls(self):
687 687
         if self._assignment_calls_calculated:
688 688
             return self._assignment_calls
689 689
         self._assignment_details = []
690  
-        result = Array(self.start_pos, Array.NOARRAY, self)
691  
-        top = result
  690
+        top = result = Array(self.start_pos, Array.NOARRAY, self)
692 691
         level = 0
693 692
         is_chain = False
694 693
         close_brackets = False
13  test/regression.py
@@ -13,8 +13,7 @@
13 13
 
14 14
 #api.set_debug_function(api.debug.print_to_stdout)
15 15
 
16  
-
17  
-class TestRegression(unittest.TestCase):
  16
+class Base(unittest.TestCase):
18 17
     def get_def(self, src, pos):
19 18
         script = api.Script(src, pos[0], pos[1], None)
20 19
         return script.get_definition()
@@ -31,6 +30,7 @@ def get_in_function_call(self, src, pos=None):
31 30
         script = api.Script(src, pos[0], pos[1], '')
32 31
         return script.get_in_function_call()
33 32
 
  33
+class TestRegression(Base):
34 34
     def test_part_parser(self):
35 35
         """ test the get_in_function_call speedups """
36 36
         s = '\n' * 100 + 'abs('
@@ -192,12 +192,13 @@ def test_named_import(self):
192 192
         assert len(api.Script(s, 1, 15, '/').get_definition()) == 1
193 193
         assert len(api.Script(s, 1, 10, '/').get_definition()) == 1
194 194
 
195  
-class TestSpeed(unittest.TestCase):
  195
+class TestSpeed(Base):
196 196
     def test_os_path_join(self):
197 197
         """ named import - jedi-vim issue #8 """
198  
-        s = "join"
199  
-        assert len(api.Script(s, 1, 15, '/').get_definition()) == 1
200  
-        assert len(api.Script(s, 1, 10, '/').get_definition()) == 1
  198
+        s = "from posixpath import join; join('', '')."
  199
+        #api.set_debug_function(api.debug.print_to_stdout)
  200
+        assert len(self.complete(s)) > 10  # is a str completion
  201
+        #api.set_debug_function(None)
201 202
 
202 203
 
203 204
 if __name__ == '__main__':

0 notes on commit 197c2f6

Please sign in to comment.
Something went wrong with that request. Please try again.