mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 15:24:46 +08:00
Fix an issue with open parentheses and function definitions right after. The fast parser should behave like the normal one and just ignore the open brackets.
This commit is contained in:
@@ -382,7 +382,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
||||
line_offset, nodes)
|
||||
last_end_line = self.current_node.parser.module.end_pos[0]
|
||||
|
||||
debug.dbg('While parsing %s, line %s slowed down the fast parser',
|
||||
debug.dbg('While parsing %s, line %s slowed down the fast parser.',
|
||||
self.module_path, line_offset)
|
||||
|
||||
line_offset = next_line_offset
|
||||
@@ -488,6 +488,16 @@ class FastTokenizer(object):
|
||||
self._closed = True
|
||||
return current
|
||||
|
||||
if value in ('def', 'class') and self._parentheses_level \
|
||||
and re.match('\n[ \t]*\Z', prefix):
|
||||
# Account for the fact that an open parentheses before a function
|
||||
# will reset the parentheses counter, but new lines before will
|
||||
# still be ignored. So check the prefix.
|
||||
|
||||
# TODO what about flow parentheses counter resets in the tokenizer?
|
||||
self._parentheses_level = 0
|
||||
return self._close()
|
||||
|
||||
# Parentheses ignore the indentation rules. The other three stand for
|
||||
# new lines.
|
||||
if self.previous[0] in (NEWLINE, INDENT, DEDENT) \
|
||||
|
||||
@@ -333,7 +333,7 @@ def test_open_parentheses():
|
||||
cache.save_parser(None, None, p, pickling=False)
|
||||
|
||||
# Now with a correct parser it should work perfectly well.
|
||||
check_fp('isinstance()\n' + func, 1)
|
||||
check_fp('isinstance()\n' + func, 1, 2)
|
||||
|
||||
|
||||
def test_strange_parentheses():
|
||||
|
||||
Reference in New Issue
Block a user