typing-exclusion-worker
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTyping Exclusion Worker
Typing排除处理工具
Purpose
用途
Execute one assigned typing batch safely and predictably:
- remove only assigned modules from mypy exclusions,
- fix surfaced typing issues in scope,
- run required checks,
- return a consistent summary for the manager/orchestrator.
安全且可预测地执行指定的类型检查批次任务:
- 仅从mypy排除列表中移除指定模块,
- 修复范围内暴露的类型问题,
- 运行必要的检查,
- 向管理者/编排器返回一致的总结。
Inputs Required
所需输入
Before starting, confirm these inputs exist in the task prompt:
- worktree/branch name,
- exact module list to remove from exclusion,
- ownership/domain boundary,
- expected validation commands (if customized).
If any are missing, ask for them before editing.
开始前,请确认任务提示中包含以下输入信息:
- 工作树/分支名称,
- 需从排除列表中移除的精确模块列表,
- 归属/领域边界,
- 预期的验证命令(如有自定义)。
若有任何信息缺失,请在编辑前询问获取。
Scope Rules (Hard Constraints)
范围规则(硬性约束)
- Only remove assigned module entries from the mypy exclusion list in .
pyproject.toml - Keep code changes in assigned scope unless a direct dependency is required to pass typing/tests.
- Do not expand to cross-team modules unless explicitly approved by the manager.
- Avoid blanket ; if unavoidable, use narrow
# type: ignorewith a short reason.ignore[code]
- 仅从中的mypy排除列表中移除指定的模块条目。
pyproject.toml - 代码修改需保持在指定范围内,除非为通过类型检查/测试必须修改直接依赖项。
- 除非获得管理者明确批准,否则不得扩展至跨团队模块。
- 避免使用宽泛的;若无法避免,请使用限定范围的
# type: ignore并附上简短理由。ignore[code]
Execution Workflow
执行流程
-
Apply exclusion change
- Remove assigned modules from the exclusion override in .
pyproject.toml
- Remove assigned modules from the exclusion override in
-
Run mypy on assigned scope
- Prefer targeted paths first for fast feedback.
- Fix errors using explicit typing patterns (narrowing, accurate return types, typed class attrs, relation-safe model access).
isinstance
-
Run tests for touched area
- Execute targeted pytest for modified modules/tests.
- Fix regressions before continuing.
-
Run pre-commit on changed files
- Run .
pre-commit run --files <changed files> - If hooks auto-fix files, rerun until clean.
- Run
-
Final verification
- Re-run targeted mypy and tests after final edits.
- Ensure no unrelated files were changed.
-
应用排除项变更
- 从的排除覆盖列表中移除指定模块。
pyproject.toml
- 从
-
在指定范围内运行mypy
- 优先针对特定路径运行以快速获取反馈。
- 使用明确的类型模式修复错误(类型收窄、精确返回类型、带类型注解的类属性、关系安全的模型访问)。
isinstance
-
运行受影响区域的测试
- 针对修改的模块/测试执行目标pytest。
- 在继续前修复回归问题。
-
对变更文件运行pre-commit
- 执行。
pre-commit run --files <changed files> - 若钩子自动修复文件,需重新运行直至无问题。
- 执行
-
最终验证
- 完成最终编辑后,重新运行目标mypy和测试。
- 确保未修改任何无关文件。
Python Typing Best Practices
Python类型检查最佳实践
- Prefer precise types over .
Any - Use type narrowing on unions before attribute access.
- Keep method overrides signature-compatible with base classes.
- Annotate class attributes in tests/helpers when inference is weak.
- Use relation objects () when stubs do not expose raw
obj.relatedattributes.*_id
- 优先使用精确类型而非。
Any - 在访问属性前对联合类型进行类型收窄。
- 方法重写需与基类的签名兼容。
- 当类型推断效果不佳时,为测试/辅助工具中的类属性添加注解。
- 当存根未暴露原始属性时,使用关系对象(
*_id)。obj.related
Required Output Template
所需输出模板
Return this exact structure at the end of each batch:
markdown
undefined每批次处理完成后,返回以下精确结构:
markdown
undefinedBatch Summary
批次总结
- Branch/worktree:
<name> - Ownership/domain:
<team-or-domain>
- 分支/工作树:
<name> - 归属/领域:
<team-or-domain>
Modules Removed From Exclusion
从排除列表中移除的模块
<module.path.one><module.path.two>
<module.path.one><module.path.two>
Files Changed
变更的文件
<path><path>
<path><path>
Key Typing Fixes
关键类型修复
<short rationale + fix><short rationale + fix>
<简短理由 + 修复内容><简短理由 + 修复内容>
Validation
验证结果
- :
mypy<pass/fail + scope> - :
pre-commit --files<pass/fail> - :
pytest<pass/fail + scope>
- :
mypy<通过/失败 + 范围> - :
pre-commit --files<通过/失败> - :
pytest<通过/失败 + 范围>
Notes
备注
- Remaining blockers:
<none or details> - Any new ignore entries:
<none or file + ignore code + reason>
undefined- 剩余阻塞项:
<无或详细信息> - 新增忽略条目:
<无或文件 + 忽略代码 + 理由>
undefinedStop Conditions (Escalate to Manager)
停止条件(上报管理者)
Stop and report instead of widening scope when:
- fixes require touching another team/domain,
- exclusion conflicts in cannot be resolved safely,
pyproject.toml - error volume indicates batch is too large and should be split.
出现以下情况时,停止操作并上报,不得扩大范围:
- 修复需要修改其他团队/领域的代码,
- 中的排除项冲突无法安全解决,
pyproject.toml - 错误数量表明批次过大,应拆分处理。