compile(): `func_type` mode is not documented
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
In 2019, compile() got a new mode="func_type" used to parse the signature of a function as AST:
- commit dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c
- issue gh-79947
>>> 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
- gh-153542
- gh-153561
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Compare the compile() function documentation with the existing ast.parse() documentation linked in the issue, focusing on the undocumented 'func_type' mode. Done means the compile() documentation either describes this mode or clearly redirects readers to the ast.parse() explanation; check linked PRs gh-153542 and gh-153561 before starting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100