Skip to content

compile(): func_type mode is not documented #153528

Description

@vstinner

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()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions