ValidationError.validator is None for a false schema, but annotated as str
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with the two false-schema branches in jsonschema/validators.py and _Error.__init__ in jsonschema/exceptions.py; compare their runtime behavior with the validator annotation and its documentation. Decide whether None should be allowed or the branches should supply another value, then check the related tests and update them to cover errors from a false schema. Done means runtime behavior, annotations, and documentation agree on the chosen behavior.
由索引模型根据 Issue 内容生成。
描述
A ValidationError produced by a false (sub)schema has validator=None and validator_value=None:
>>> import jsonschema
>>> e = next(jsonschema.Draft202012Validator({"properties": {"a": False}}).iter_errors({"a": 1}))
>>> e.validator, e.validator_value, e.schema
(None, None, False)
That comes from the two False-schema branches, which pass validator=None
(validators.py#L377,
#L412),
while _Error.__init__ annotates the parameter as validator: str
(exceptions.py#L63),
and the docs describe validator as "the name of the failed keyword". There is no keyword for a boolean schema,
so None is a reasonable value at runtime -- but the annotation does not allow it.
This matters downstream because typeshed's types-jsonschema mirrors the annotation (validator: str | Unset, since
python/typeshed#15353), so type checkers treat error.validator as always a string, and code that relies on that
(e.g. error.validator.upper()) passes type checking and fails on errors from false schemas.
Which side would you consider correct?
- the annotation (and docs) should admit
Nonefor errors raised by a booleanfalseschema, or - the
False-schema branches should pass something else.
Happy to send a PR for whichever you prefer, and to follow up in typeshed accordingly.
Seen on jsonschema 4.25.1 and on main (c497561).
- 主要语言
- Python
- 星标
- 5k
- 派生
- 741
- 平均合并
- 4 天 17 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-jsonschema/jsonschema 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
python-jsonschema/jsonschema#1610 · 1 条评论 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
python-jsonschema/jsonschema#1588 · 2 条评论 ·
维护者通常 6 天内回复
-
Iterator error contexts lose parent links and absolute paths可能重新可做 @DawnofGenX 于 59 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
python-jsonschema/jsonschema#1584 · 3 条评论 ·
维护者通常 6 天内回复
-
regex format checker crashes with RecursionError on deeply nested patterns可能已有人在做 @DawnofGenX 于 59 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
python-jsonschema/jsonschema#1538 · 1 条评论 ·
维护者通常 6 天内回复
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponent可能重新可做 关联的 PR 已关闭且未合并。 未关闭Needs Test Upstream
难度 2/5 1-3 小时 新手友好度 78/100
python-jsonschema/jsonschema#1511 · 1 条评论 ·
维护者通常 6 天内回复
查看 python-jsonschema/jsonschema 的全部 Issue
相似的 Issue
-
难度 1/5 1-3 小时 新手友好度 78/100
web-push-libs/pywebpush#216 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
AgriciDaniel/claude-seo#572 ·
维护者通常 5 天内回复
-
area:print-dispatch
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
area: docs domain: technical-writing good first issue type: documentation
难度 2/5 1-3 小时 新手友好度 80/100
Deepak3699/Ai_Mentor#919 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复