davidhalter / jedi

Awesome autocompletion, static analysis and refactoring library for python
http://jedi.readthedocs.io
Other
5.8k stars 508 forks source link

IndexError: list index out of range #237

Closed srusskih closed 11 years ago

srusskih commented 11 years ago
a = """a
for a in range(10):
   print a"""
import jedi
script = jedi.Script(a, 1, 1, '')
script.completions()

Got:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/storage/PythonProjects/SublimeJEDI/<ipython console> in <module>()

/storage/PythonProjects/SublimeJEDI/jedi/api_classes.py in wrapper(*args, **kwds)
     42     @functools.wraps(func)
     43     def wrapper(*args, **kwds):
---> 44         result = func(*args, **kwds)
     45         _clear_caches()
     46         return result

/storage/PythonProjects/SublimeJEDI/jedi/api.py in completions(self)
     92 
     93         try:
---> 94             scopes = list(self._prepare_goto(path, True))
     95         except NotFoundError:
     96             scopes = []

/storage/PythonProjects/SublimeJEDI/jedi/api.py in _prepare_goto(self, goto_path, is_like_search)
    173         under cursor.
    174         """
--> 175         debug.dbg('start: %s in %s' % (goto_path, self._parser.user_scope))
    176 
    177         user_stmt = self._parser.user_stmt

/storage/PythonProjects/SublimeJEDI/jedi/api.py in _parser(self)
     73     def _parser(self):
     74         """ lazy parser."""
---> 75         return self._module.parser
     76 
     77     @api_classes._clear_caches_after_call

/storage/PythonProjects/SublimeJEDI/jedi/modules.py in parser(self)
    114             # default), therefore fill the cache here.

    115             self._parser = fast_parser.FastParser(self.source, self.path,
--> 116                                                         self.position)
    117             # don't pickle that module, because it's changing fast

    118             cache.save_module(self.path, self.name, self._parser,

/storage/PythonProjects/SublimeJEDI/jedi/fast_parser.py in __call__(self, source, module_path, user_position)
     71         else:
     72             p = pi.parser  # pi is a `cache.ParserCacheItem`
---> 73             p.update(source, user_position)
     74         return p
     75 

/storage/PythonProjects/SublimeJEDI/jedi/fast_parser.py in update(self, code, user_position)
    222         self.reset_caches()
    223 
--> 224         self._parse(code)
    225 
    226     def _scan_user_scope(self, sub_module):

/storage/PythonProjects/SublimeJEDI/jedi/fast_parser.py in _parse(self, code)
    331                 #print '#'*45,line_offset, p and p.end_pos, '\n', code_part

    332                 p, node = self._get_parser(code_part, code[start:],
--> 333                                            line_offset, nodes, not is_first)
    334 
    335                 if is_first and p.module.subscopes:

/storage/PythonProjects/SublimeJEDI/jedi/fast_parser.py in _get_parser(self, code, parser_code, line_offset, nodes, no_docstr)
    394                                self.user_position, offset=(line_offset, 0),
    395                                is_fast_parser=True, top_module=self.module,
--> 396                                no_docstr=no_docstr)
    397             p.module.parent = self.module
    398         else:

/storage/PythonProjects/SublimeJEDI/jedi/parsing.py in __init__(self, source, module_path, user_position, no_docstr, offset, is_fast_parser, top_module)
     66         self.top_module = top_module or self.module
     67         try:
---> 68             self._parse()
     69         except (common.MultiLevelStopIteration, StopIteration):
     70             # StopIteration needs to be added as well, because python 2 has a

/storage/PythonProjects/SublimeJEDI/jedi/parsing.py in _parse(self)
    638                     stmt.parent = use_as_parent_scope
    639                 try:
--> 640                     func.returns.append(stmt)
    641                     # start_pos is the one of the return statement

    642                     stmt.start_pos = s

/storage/PythonProjects/SublimeJEDI/jedi/fast_parser.py in __getattr__(self, name)
     38             raise AttributeError('Not available!')
     39         else:
---> 40             return getattr(self.parsers[0].module, name)
     41 
     42     @property

IndexError: list index out of range
In [148]: jedi.__version__
Out[148]: (0, 6, 0)
srusskih commented 11 years ago

Works. Sorry.