Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Iterator error contexts lose parent links and absolute paths

未关闭 适合新手
#1,584 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@DawnofGenX 已经在做这个了。

开始于 2026年10月5日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

首先定位 ValidationError 和 SchemaError 构造函数,并复现 issue 中的迭代器示例。检查现有的回归测试,以了解上下文和 parent 行为,然后为这两个错误类分别覆盖一次性迭代器上下文,以及列表和元组上下文。完成的标准是子项保留其 parent 链接,并生成包含 parent 路径的绝对路径。

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

描述

Problem

Passing an iterator as ValidationError(context=...) retains its children, but does not set their parent. The iterator is consumed by self.context = list(context), then iterated again when assigning parents. This also affects SchemaError.

from jsonschema.exceptions import ValidationError

child = ValidationError("child", path=["name"], schema_path=[0, "type"])
parent = ValidationError(
    "parent",
    path=["record"],
    schema_path=["properties", "record", "anyOf"],
    context=iter([child]),
)
print(parent.context == [child])  # True
print(child.parent is parent)    # False (expected True)
print(child.json_path)           # $.name (expected $.record.name)

Lists and tuples assign the parent correctly. Setting parents from the stored self.context instead of the original iterable should preserve the same behavior for one-shot iterators.

Reproduced on main (51cd75e39), macOS, Python 3.12.13. A regression test fails for iterator contexts with both error classes and passes for list/tuple contexts.

Investigated with Codex assistance.

主要语言
Python
星标
5k
派生
694
平均合并
1 天 20 小时
30 天内合并 PR
6

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

python-jsonschema/jsonschema 的其他 Issue

查看 python-jsonschema/jsonschema 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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