`configparser.RawConfigParser` stub does not account for non-string options
未关闭
适合新手
还没有人认领这个 Issue。
stubs: false positive
- 主要语言
- Python
- 星标
- 5.1k
- 派生
- 2.1k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 82
描述
The stub for configparser.RawConfigParser.set has its value argument typed as str | None (source) when it can accept lots of other types and is leading to a false positive in mypy for me.
Consider this valid script:
from configparser import RawConfigParser
cfg = RawConfigParser()
cfg.add_section("default")
cfg.set("default", "some_option1", True)
r1 = cfg.get("default", "some_option1")
print(r1, type(r1))
cfg.set("default", "some_option2", 1)
r2 = cfg.get("default", "some_option2")
print(r2, type(r2))
cfg.set("default", "some_option3", b"bytes")
r3 = cfg.get("default", "some_option3")
print(r3, type(r3))
It prints:
True <class 'bool'>
1 <class 'int'>
b'bytes' <class 'bytes'>
However, mypy flags this code for the reason described above:
test.py:6: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bool"; expected "Optional[str]"
test.py:11: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "int"; expected "Optional[str]"
test.py:15: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bytes"; expected "Optional[str]"
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 stdlib/configparser.pyi 第 133 行附近开始,将 RawConfigParser.set 的签名与 issue 中展示的行为进行比较。使用 mypy 运行提供的脚本以复现误报,然后验证 boolean、integer 和 bytes 值能够无错误地被接受,同时现有的 get 行为仍然得到覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100