json.dump/dumps shouldn't allow `Any` when `default` is None
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
定位 json.dump 和 json.dumps 的存根,并检查它们的重载如何处理默认参数。根据所得类型检查 issue 中的示例;完成的标准是:不带默认参数的调用会拒绝不受支持的输入,而带默认参数的调用仍保持适当的类型。
由索引模型根据 Issue 内容生成。
描述
When default is None, we know what types are serialisable.
Thus,
import json
import types
import typing
def x(data: typing.Mapping[str, str]) -> str:
return json.dumps(data)
def y():
return json.dumps(types.MappingProxyType({}))
Shouldn't type-check.
Running this fails with:
File /opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/json/encoder.py:180, in JSONEncoder.default(self, o)
161 def default(self, o):
162 """Implement this method in a subclass such that it returns
163 a serializable object for ``o``, or calls the base implementation
164 (to raise a ``TypeError``).
(...) 178
179 """
--> 180 raise TypeError(f'Object of type {o.__class__.__name__} '
181 f'is not JSON serializable')
TypeError: Object of type mappingproxy is not JSON serializable
Type-checking JSONEncoder itself would be much harder, but the more-commonly-used functions should be doable via overloads.
- 主要语言
- Python
- 星标
- 5.1k
- 派生
- 2.1k
- 平均合并
- 2 天 7 分钟
- 30 天内合并 PR
- 116
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/typeshed 的其他 Issue
-
`networkx.set_edge_attributes` should support scalar value + name可能已有人在做 @Fire162 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
false alarm on decode call可能已有人在做 @jw9829 于 37 天前认领。 未关闭help wanted stubs: false positive
难度 2/5 1-3 小时 新手友好度 76/100
python/typeshed#16441 · 1 条评论 ·
维护者通常 1 天内回复
-
Don't run pyright basic checks on projects with strict pyright settings in CI可能已有人在做 @Mohith1612 于 73 天前认领。 未关闭project: infrastructure
难度 2/5 1-3 小时 新手友好度 68/100
python/typeshed#16005 · 1 条评论 ·
维护者通常 1 天内回复
-
stubs: improvement
难度 2/5 1-3 小时 新手友好度 72/100
python/typeshed#15548 · 5 条评论 ·
维护者通常 1 天内回复
-
stubs: improvement
难度 2/5 1-3 小时 新手友好度 64/100
python/typeshed#15529 · 5 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 78/100
elviskahoro/sdk-python-attio#144 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
RenyiELBO raises TypeError when model has no sample sites可能已有人在做 @alibb007 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复