python / python/typeshed

Consistently mark types with `| MaybeNone` whenever it is applicable

未关闭
#12,822 6 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
5.1k
派生
2.1k
平均合并
1 天 19 小时
30 天内合并 PR
82

描述

I noticed that there's a special type alias MaybeNone that represents this specific intent:

We didn't dare to change the type to X | None so instead we changed it to Any

You can find an example in a relatively recent addition of this.

And while this approach makes me very sad, it is good that such cases are marked with MaybeNone, for the purpose of looking at them specially. Maybe some type checker will arise that will have specific handling for it and do something smarter instead.

With that in mind, it would be good to ensure that all such cases are consistently marked.

I noticed at least one case that is not marked like this. It has | Any directly written instead of | MaybeNone. This is in re.match.group*:

https://github.com/python/typeshed/blob/6feca188689e14cdacd8dbf8bc9cf0635993027a/stdlib/re.pyi#L93-L117

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 stdlib/re.pyi 开始,尤其检查第 93–117 行附近的 re.match.group* 定义,并将其与 stdlib/_typeshed/init.pyi 中的 MaybeNone 别名进行比较。检查 stubs 中使用 Any 表示这一意图的类似情况;完成标准是适用的情况都一致改用 MaybeNone,并且没有发现未标记的例外。

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

评估

技术栈
python
领域
tooling
Issue 类型
重构
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

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