1
0
forked from VimPlug/jedi

the fast parser was able to return wrong sub parsers, because the sometimes hashes were not updated, fixes #396.

This commit is contained in:
Dave Halter
2014-05-04 16:36:41 +02:00
parent 16fd7f5424
commit a4b9ccc2e7
2 changed files with 16 additions and 12 deletions

View File

@@ -72,14 +72,14 @@ class CachedFastParser(type):
class ParserNode(object):
def __init__(self, parser, code, parent=None):
self.parent = parent
self.code = code
self.hash = hash(code)
self.children = []
# must be created before new things are added to it.
self.save_contents(parser)
self.save_contents(parser, code)
def save_contents(self, parser):
def save_contents(self, parser, code):
self.code = code
self.hash = hash(code)
self.parser = parser
try:
@@ -325,7 +325,7 @@ class FastParser(use_metaclass(CachedFastParser)):
if self.current_node is None:
self.current_node = ParserNode(new, '')
else:
self.current_node.save_contents(new)
self.current_node.save_contents(new, '')
self.parsers.append(new)
is_first = False
@@ -333,7 +333,7 @@ class FastParser(use_metaclass(CachedFastParser)):
if self.current_node is None:
self.current_node = ParserNode(p, code_part_actually_used)
else:
self.current_node.save_contents(p)
self.current_node.save_contents(p, code_part_actually_used)
else:
if node is None:
self.current_node = \

View File

@@ -59,18 +59,22 @@ def test_carriage_return_splitting():
def test_change_and_undo():
cache.parser_cache.pop(None, None)
def fp(src):
p = FastParser(u(src))
cache.save_parser(None, None, p, pickling=False)
# TODO Don't just take the first line, the whole thing should be the same.
# Need to refactor the parser first, though.
print(repr(p.module.get_code()))
first_line = p.module.get_code().splitlines()[0]
assert first_line == src
# TODO Don't change get_code, the whole thing should be the same.
# -> Need to refactor the parser first, though.
assert src == p.module.get_code()[:-1]
cache.parser_cache.pop(None, None)
func_before = 'def func():\n pass\n'
fp(func_before + 'a')
fp(func_before + 'b')
fp(func_before + 'a')
cache.parser_cache.pop(None, None)
fp('a')
fp('b')
fp('a')