Fix some issues with async funcs

This commit is contained in:
Dave Halter
2020-04-04 04:01:15 +02:00
parent 7f0dd35c37
commit e1632cdadc

View File

@@ -15,6 +15,7 @@ from parso.python.parser import Parser
from parso.python.tree import EndMarker, PythonErrorLeaf from parso.python.tree import EndMarker, PythonErrorLeaf
from parso.python.tokenize import PythonToken from parso.python.tokenize import PythonToken
from parso.python.token import PythonTokenTypes from parso.python.token import PythonTokenTypes
from parso.tree import search_ancestor
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
DEBUG_DIFF_PARSER = False DEBUG_DIFF_PARSER = False
@@ -164,6 +165,12 @@ def _func_or_class_has_suite(node):
return node.type in ('classdef', 'funcdef') and node.children[-1].type == 'suite' return node.type in ('classdef', 'funcdef') and node.children[-1].type == 'suite'
def _get_suite_func_or_class_parent(node):
while node.parent.type in ('funcdef', 'classdef', 'async_stmt', 'async_funcdef', 'decorated'):
node = node.parent
return node
def _suite_or_file_input_is_valid(pgen_grammar, stack): def _suite_or_file_input_is_valid(pgen_grammar, stack):
if not _flows_finished(pgen_grammar, stack): if not _flows_finished(pgen_grammar, stack):
return False return False
@@ -467,7 +474,7 @@ class _NodesTreeNode(object):
if self.tree_node.type == 'file_input': if self.tree_node.type == 'file_input':
self.indentation = 0 self.indentation = 0
else: else:
self.indentation = self.tree_node.parent.start_pos[-1] self.indentation = _get_suite_func_or_class_parent(self.tree_node).start_pos[1]
def finish(self): def finish(self):
children = [] children = []