mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Make sure iter_funcdefs includes async functions with decorators, fixes #98
This commit is contained in:
@@ -57,7 +57,11 @@ from parso.utils import split_lines
|
||||
_FLOW_CONTAINERS = set(['if_stmt', 'while_stmt', 'for_stmt', 'try_stmt',
|
||||
'with_stmt', 'async_stmt', 'suite'])
|
||||
_RETURN_STMT_CONTAINERS = set(['suite', 'simple_stmt']) | _FLOW_CONTAINERS
|
||||
_FUNC_CONTAINERS = set(['suite', 'simple_stmt', 'decorated']) | _FLOW_CONTAINERS
|
||||
|
||||
_FUNC_CONTAINERS = set(
|
||||
['suite', 'simple_stmt', 'decorated', 'async_funcdef']
|
||||
) | _FLOW_CONTAINERS
|
||||
|
||||
_GET_DEFINITION_TYPES = set([
|
||||
'expr_stmt', 'sync_comp_for', 'with_stmt', 'for_stmt', 'import_name',
|
||||
'import_from', 'param', 'del_stmt',
|
||||
|
||||
@@ -222,3 +222,19 @@ def test_is_definition(code, name_index, is_definition, include_setitem):
|
||||
name = name.get_next_leaf()
|
||||
|
||||
assert name.is_definition(include_setitem=include_setitem) == is_definition
|
||||
|
||||
|
||||
def test_iter_funcdefs():
|
||||
code = dedent('''
|
||||
def normal(): ...
|
||||
async def asyn(): ...
|
||||
@dec
|
||||
def dec_normal(): ...
|
||||
@dec1
|
||||
@dec2
|
||||
async def dec_async(): ...
|
||||
def broken
|
||||
''')
|
||||
module = parse(code, version='3.8')
|
||||
func_names = [f.name.value for f in module.iter_funcdefs()]
|
||||
assert func_names == ['normal', 'asyn', 'dec_normal', 'dec_async']
|
||||
|
||||
Reference in New Issue
Block a user