In 2019, compile() got a new mode="func_type" used to parse the signature of a function as AST:
>>> compile('() -> int', '<string>', 'func_type', flags=ast.PyCF_ONLY_AST)
FunctionType(argtypes=[], returns=Name(id='int', ctx=Load()))
>>> import ast; ast.parse('() -> int', '<string>', 'func_type')
FunctionType(argtypes=[], returns=Name(id='int', ctx=Load()))
It's tested by test_type_comments using ast.parse() function.
The 'func_type' mode is documented in ast.parse() documentation:
In addition, if mode is 'func_type', the input syntax is modified to correspond to PEP 484 “signature type comments”, e.g. (str, int) -> List[str].
But it's not documented in the compile() function documentation. Should it be documented there as well? Maybe at least by redirecting to ast.parse()?
Linked PRs
In 2019, compile() got a new
mode="func_type"used to parse the signature of a function as AST:It's tested by
test_type_commentsusingast.parse()function.The
'func_type'mode is documented in ast.parse() documentation:But it's not documented in the compile() function documentation. Should it be documented there as well? Maybe at least by redirecting to ast.parse()?
Linked PRs
mode="func_type"incompile()#153542mode="func_type"incompile()#153561