mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-25 17:58:35 +08:00
fix another IndexError, due to empty files (e.g. __init__.py)
This commit is contained in:
+9
-1
@@ -331,6 +331,10 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
|
|
||||||
def _parse(self, code):
|
def _parse(self, code):
|
||||||
""" :type code: str """
|
""" :type code: str """
|
||||||
|
def empty_parser():
|
||||||
|
new, temp = self._get_parser('', '', 0, [])
|
||||||
|
return new
|
||||||
|
|
||||||
parts = self._split_parts(code)
|
parts = self._split_parts(code)
|
||||||
self.parsers[:] = []
|
self.parsers[:] = []
|
||||||
|
|
||||||
@@ -338,6 +342,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
start = 0
|
start = 0
|
||||||
p = None
|
p = None
|
||||||
is_first = True
|
is_first = True
|
||||||
|
|
||||||
for code_part in parts:
|
for code_part in parts:
|
||||||
lines = code_part.count('\n') + 1
|
lines = code_part.count('\n') + 1
|
||||||
if is_first or line_offset >= p.end_pos[0]:
|
if is_first or line_offset >= p.end_pos[0]:
|
||||||
@@ -360,7 +365,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
if is_first and p.module.subscopes:
|
if is_first and p.module.subscopes:
|
||||||
# special case, we cannot use a function subscope as a
|
# special case, we cannot use a function subscope as a
|
||||||
# base scope, subscopes would save all the other contents
|
# base scope, subscopes would save all the other contents
|
||||||
new, temp = self._get_parser('', '', 0, [])
|
new = empty_parser()
|
||||||
if self.current_node is None:
|
if self.current_node is None:
|
||||||
self.current_node = ParserNode(new, code)
|
self.current_node = ParserNode(new, code)
|
||||||
else:
|
else:
|
||||||
@@ -389,6 +394,9 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
line_offset += lines
|
line_offset += lines
|
||||||
start += len(code_part) + 1 # +1 for newline
|
start += len(code_part) + 1 # +1 for newline
|
||||||
|
|
||||||
|
if not self.parsers:
|
||||||
|
self.parsers.append(empty_parser())
|
||||||
|
|
||||||
#print(self.parsers[0].module.get_code())
|
#print(self.parsers[0].module.get_code())
|
||||||
del code
|
del code
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user