python / python/cpython

compile(): `func_type` mode is not documented

未关闭
#153,528 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

docs
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

将 compile() 函数的文档与 issue 中链接的现有 ast.parse() 文档进行比较,重点关注未记录的 'func_type' 模式。完成的标准是:compile() 文档要么描述此模式,要么明确将读者引导至 ast.parse() 的说明;开始前请检查已链接的 PR gh-153542 和 gh-153561。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
documentation
Issue 类型
文档
难度
1/5
预计耗时
1 小时以内
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。