From d71de02ab85b24ab202cfa7e66038aaa635292fc Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 17 Oct 2026 01:19:19 +0800 Subject: [PATCH] chore(types): expand strict gate to 204 files --- docs/code-quality.md | 2 +- docs/refactor/optimization-checklist.md | 6 +- mypy.ini | 19 +++ .../architecture/dependency-baseline.json | 7 +- .../fixtures/architecture/mypy-baseline.json | 130 +----------------- 5 files changed, 33 insertions(+), 131 deletions(-) diff --git a/docs/code-quality.md b/docs/code-quality.md index 32c7af12b..e62aaeed3 100644 --- a/docs/code-quality.md +++ b/docs/code-quality.md @@ -75,7 +75,7 @@ uv run --locked --no-sync python scripts/architecture/complexity.py 回调和返回值类型;全仓错误计数为零并不保证单独纳入 strict frontier 后也为零。 2026-10-16 开始逐文件清理类型债务,`app/domain/title.py` 通过局部可空类型声明保留 -既有搜索解析行为,并纳入严格清单;当前清单共 185 个文件(184 个生产文件和 1 个脚本)。 +既有搜索解析行为,并纳入严格清单;当前清单共 204 个文件(203 个生产文件和 1 个脚本)。 每个生产文件完成针对性测试后独立提交,并纳入严格门禁。每批集中同步真实下降的 类型基线和指标文档,运行完整本地单测与适用门禁后统一推送;不逐文件等待远端 CI。 验收同时检查完整严格清单与全宿主 Linux 分析,避免 `follow_imports = skip` 隐藏依赖 diff --git a/docs/refactor/optimization-checklist.md b/docs/refactor/optimization-checklist.md index bdc6c6082..1eb78108f 100644 --- a/docs/refactor/optimization-checklist.md +++ b/docs/refactor/optimization-checklist.md @@ -100,15 +100,15 @@ ARCH-201 至 ARCH-204 均达到实现、验证、提交、推送和远端门禁 | 指标 | 当前值 | 解释 | |---|---:|---| -| 宿主 Python 模块 / 内部依赖边 | 1122 / 9,565 | `dependency-baseline.json` 当前快照;Telegram Rich Message 失败降级复用 `app.schemas.exception` 的 `ImmediateException`,新增 2 条合法依赖边(含父包展开),未新增模块或 SCC。目录监控成功通知在批次完成后复用主事件循环开启静默窗口,新增 2 条合法 Chain 到 Runtime 依赖边(含父包展开),未新增模块或 SCC。成功通知聚合复用既有 owner 和领域模型,统一交由通知模板渲染;移除汇总发送端的模板上下文直连后,原聚合实现的 14 条新增依赖边减为 12 条,未新增模块或 SCC。社区勋章名单读取复用 `app.foundation.url` 标准化 GitHub 镜像地址,新增 2 条合法依赖边(含父包展开),未新增模块或 SCC。专辑订阅入库对账新增 1 个 Chain owner 和 18 条合法依赖边(含父包展开),仍经注入 Port 读取历史并通过既有 mutation 写入;订阅业务活动新增 4 个模块和 50 条合法内部依赖边(含父包展开),Application 仅定义事实与持久化 Port,DB Adapter/Oper 实现存取,组合根注入,未增加 Application/Chain 到具体 Adapter 或数据库的直连;插件实例校验复用 `app.domain.plugin` 的物理身份规则,兼容下划线 ID,新增 2 条合法依赖边(含父包展开);种子失败冷却复用 `app.domain.torrent` 的限流语义,新增 1 条合法导入边;系统设置合同按 `app.application.settings` 包组织,系统设置 API 端点独立按 `app.api.endpoints.settings` 归档;消息音乐交互由 `app.chain.music_interaction` 包中的音乐解析/展示与订阅协调模块处理;已整理下载的站点字幕经 `app.chain.transfer` 自动整理队列完成命名与归档;网络连通性检测按 `app.application.nettest` 归档;工作流添加下载动作由 `app.workflow.actions.add_download` 转换工作流 Schema 为下载链领域上下文,新增 5 条合法模块导入边,资源过滤动作复用同一还原再新增 6 条;LLM 独占连接关闭复用宿主线程池;歌词字形转换复用 `app.foundation.text`;订阅创建使用 `app.domain.context.MediaInfo` 和运行时配置端口,将非 TMDB 影视身份投影为 TMDB 身份;本次安全与可靠性修复新增 4 条合法依赖边:WebAgent 复用渠道类型、宿主历史清理复用文件系统代理、两个下载器复用纯领域种子哈希规则,未新增模块或 SCC;IP 归属地适配器复用 `app.schemas.common.JsonData` 声明原始 JSON 返回,新增 2 条合法类型依赖边(含父包展开),未新增模块、循环或越层依赖;TMDb 认证与片单读取复用模块既有异常,新增 2 条同模块依赖边;Session 类型使扫描器识别原有两处 close,发送与会话关闭路径未变 | +| 宿主 Python 模块 / 内部依赖边 | 1122 / 9,568 | `dependency-baseline.json` 当前快照;Telegram Rich Message 失败降级复用 `app.schemas.exception` 的 `ImmediateException`,新增 2 条合法依赖边(含父包展开),未新增模块或 SCC。目录监控成功通知在批次完成后复用主事件循环开启静默窗口,新增 2 条合法 Chain 到 Runtime 依赖边(含父包展开),未新增模块或 SCC。成功通知聚合复用既有 owner 和领域模型,统一交由通知模板渲染;移除汇总发送端的模板上下文直连后,原聚合实现的 14 条新增依赖边减为 12 条,未新增模块或 SCC。社区勋章名单读取复用 `app.foundation.url` 标准化 GitHub 镜像地址,新增 2 条合法依赖边(含父包展开),未新增模块或 SCC。专辑订阅入库对账新增 1 个 Chain owner 和 18 条合法依赖边(含父包展开),仍经注入 Port 读取历史并通过既有 mutation 写入;订阅业务活动新增 4 个模块和 50 条合法内部依赖边(含父包展开),Application 仅定义事实与持久化 Port,DB Adapter/Oper 实现存取,组合根注入,未增加 Application/Chain 到具体 Adapter 或数据库的直连;插件实例校验复用 `app.domain.plugin` 的物理身份规则,兼容下划线 ID,新增 2 条合法依赖边(含父包展开);种子失败冷却复用 `app.domain.torrent` 的限流语义,新增 1 条合法导入边;系统设置合同按 `app.application.settings` 包组织,系统设置 API 端点独立按 `app.api.endpoints.settings` 归档;消息音乐交互由 `app.chain.music_interaction` 包中的音乐解析/展示与订阅协调模块处理;已整理下载的站点字幕经 `app.chain.transfer` 自动整理队列完成命名与归档;网络连通性检测按 `app.application.nettest` 归档;工作流添加下载动作由 `app.workflow.actions.add_download` 转换工作流 Schema 为下载链领域上下文,新增 5 条合法模块导入边,资源过滤动作复用同一还原再新增 6 条;LLM 独占连接关闭复用宿主线程池;歌词字形转换复用 `app.foundation.text`;订阅创建使用 `app.domain.context.MediaInfo` 和运行时配置端口,将非 TMDB 影视身份投影为 TMDB 身份;本次安全与可靠性修复新增 4 条合法依赖边:WebAgent 复用渠道类型、宿主历史清理复用文件系统代理、两个下载器复用纯领域种子哈希规则,未新增模块或 SCC;IP 归属地适配器复用 `app.schemas.common.JsonData` 声明原始 JSON 返回,新增 2 条合法类型依赖边(含父包展开),未新增模块、循环或越层依赖;TMDb 认证与片单读取复用模块既有异常,新增 2 条同模块依赖边;Session 类型使扫描器识别原有两处 close,发送与会话关闭路径未变;Audiences 构造参数复用既有 RequestUtils 类型,新增 3 条合法依赖边(含父包展开),未新增模块或 SCC | | 非平凡 SCC | 1 | 仅保留精确 containment 的 29 模块 TMDB 移植包环 | | 跨层 DB 边界债务 | 0 | Application、Chain、API、Agent、Runtime、Workflow 到 DB 的受控债务均为零 | | Model/Oper 事务债务 | 0 | 自建 Session、自动事务装饰器、直接 commit/rollback 等基线均为零 | | Module Contract | 215 specs / 211 methods / 263 calls | 动态方法名为 0;分类事实富化通过显式合同进入插件调度,旧 YAML 分类方法已移除;download 新增 custom_words 可选参数,旧 provider 签名通过显式合同兼容 | | Event Contract | 53 | 均已有 payload model,但当前全部是 diagnostic enforcement | -| Python 源码量 | 372,940 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 | +| Python 源码量 | 373,037 行 | 本次重新扫描物理行数,排除 `app/plugins/**`;74 个文件超过 1,000 行,12 个超过 2,000 行;源码尺寸仅作观察 | | 长方法 | 309 个超过 80 行 | 本次 AST 扫描排除 `app/plugins/**`;61 个超过 150 行,17 个超过 250 行;新增函数仍受 C901/嵌套深度门禁约束 | -| 全量 mypy 历史债务 | 7,898 / 388 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项,逐文件逐错误码无增长 | +| 全量 mypy 历史债务 | 7,494 / 371 文件 | 通知排版补齐 Slack 消息块类型,历史债务减少 2 项;工作流资源过滤改用领域对象调用过滤链,恢复的节点输出在消费前归一化,并收紧可空资源列表的类型低水位;消息媒体交互类型债务已清零,canonical Facade 与 endpoint 类型边界已补齐,低水位只允许继续下降;微信 ClawBot 入站 item_list 媒体解析改为按子项键名分派后,类型错误减少 4 项;站点解析器分享率改用浮点初值,类型错误减少 20 项;本次下载与文件安全修复再减少 3 项;Transmission 进度回退值归一化再减少 2 项,逐文件逐错误码无增长 | | Ruff 历史诊断 | 98 | 低水位门禁通过,但规则集只覆盖 `E4/E7/E9/F/I` | | 覆盖率固定基线 | Application 80.00%,Domain 80.00% | Chain、Runtime、Agent、Adapter、Startup 未进入包级覆盖率门禁 | diff --git a/mypy.ini b/mypy.ini index 61b4b8ddc..6f1ceb8e7 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,6 +7,7 @@ follow_imports = skip show_error_codes = True pretty = True files = + app/domain/site.py, app/domain/scraper.py, app/domain/episode.py, app/domain/media.py, @@ -17,6 +18,7 @@ files = app/domain/meta/customization.py, app/domain/meta/releasegroup.py, app/domain/meta/streamingplatform.py, + app/foundation/size.py, app/foundation/dom.py, app/foundation/text.py, app/foundation/url.py, @@ -33,6 +35,23 @@ files = app/adapters/system/fsworker.py, app/adapters/system/resource.py, app/agent/contracts.py, + app/modules/indexer/parser/__init__.py, + app/modules/indexer/parser/discuz.py, + app/modules/indexer/parser/file_list.py, + app/modules/indexer/parser/gazelle.py, + app/modules/indexer/parser/hddolby.py, + app/modules/indexer/parser/ipt.py, + app/modules/indexer/parser/mtorrent.py, + app/modules/indexer/parser/nexus_audiences.py, + app/modules/indexer/parser/nexus_hhanclub.py, + app/modules/indexer/parser/nexus_php.py, + app/modules/indexer/parser/nexus_project.py, + app/modules/indexer/parser/nexus_rabbit.py, + app/modules/indexer/parser/small_horse.py, + app/modules/indexer/parser/tnode.py, + app/modules/indexer/parser/torrent_leech.py, + app/modules/indexer/parser/unit3d.py, + app/modules/indexer/parser/yema.py, app/modules/douban/scraper.py, app/modules/dingtalk/dingtalk.py, app/schemas/exception.py, diff --git a/tests/fixtures/architecture/dependency-baseline.json b/tests/fixtures/architecture/dependency-baseline.json index fb6856d17..31a41af74 100644 --- a/tests/fixtures/architecture/dependency-baseline.json +++ b/tests/fixtures/architecture/dependency-baseline.json @@ -943,8 +943,8 @@ "runtime_only": true } }, - "edge_count": 9565, - "edge_sha256": "470543337cae761f4c44f9a111389b89d28553fbfb92ce6d3bc2eb7c6ea8b3c3", + "edge_count": 9568, + "edge_sha256": "eeb29fd095c84820c520d3697a1319607cd1614188bd39a85c3995416a009979", "edges": [ "app -> app.foundation", "app -> app.foundation.environment", @@ -7601,6 +7601,9 @@ "app.modules.indexer.parser.mtorrent -> app.modules.indexer.parser", "app.modules.indexer.parser.mtorrent -> app.runtime", "app.modules.indexer.parser.mtorrent -> app.runtime.log", + "app.modules.indexer.parser.nexus_audiences -> app.adapters", + "app.modules.indexer.parser.nexus_audiences -> app.adapters.network", + "app.modules.indexer.parser.nexus_audiences -> app.adapters.network.http", "app.modules.indexer.parser.nexus_audiences -> app.foundation", "app.modules.indexer.parser.nexus_audiences -> app.foundation.dom", "app.modules.indexer.parser.nexus_audiences -> app.foundation.size", diff --git a/tests/fixtures/architecture/mypy-baseline.json b/tests/fixtures/architecture/mypy-baseline.json index 9d8278301..258dfdcb7 100644 --- a/tests/fixtures/architecture/mypy-baseline.json +++ b/tests/fixtures/architecture/mypy-baseline.json @@ -1315,149 +1315,29 @@ "attr-defined": 1, "empty-body": 1, "no-any-return": 2, - "no-untyped-call": 3, "no-untyped-def": 1, "return-value": 4, "type-arg": 19, "var-annotated": 5 }, - "app/modules/indexer/parser/__init__.py": { - "arg-type": 14, - "assignment": 4, - "comparison-overlap": 1, - "no-untyped-call": 4, - "no-untyped-def": 14, - "return-value": 1, - "type-arg": 3, - "var-annotated": 3 - }, "app/modules/indexer/parser/bitpt.py": { "arg-type": 4, - "assignment": 24, - "attr-defined": 1, - "empty-body": 1, - "no-untyped-call": 1, - "no-untyped-def": 9, + "assignment": 7, + "no-untyped-def": 1, "override": 1, - "type-arg": 1, "union-attr": 2 }, - "app/modules/indexer/parser/discuz.py": { - "assignment": 3, - "no-untyped-call": 1, - "no-untyped-def": 5, - "type-arg": 1 - }, - "app/modules/indexer/parser/file_list.py": { - "assignment": 4, - "no-untyped-call": 3, - "no-untyped-def": 5, - "type-arg": 1 - }, - "app/modules/indexer/parser/gazelle.py": { - "assignment": 4, - "no-untyped-call": 1, - "no-untyped-def": 5, - "type-arg": 1 - }, - "app/modules/indexer/parser/hddolby.py": { - "assignment": 13, - "no-untyped-call": 1, - "no-untyped-def": 7, - "type-arg": 1 - }, - "app/modules/indexer/parser/ipt.py": { - "assignment": 4, - "no-untyped-call": 1, - "no-untyped-def": 5, - "return": 1, - "type-arg": 1 - }, - "app/modules/indexer/parser/mtorrent.py": { - "assignment": 11, - "empty-body": 1, - "index": 2, - "no-untyped-def": 6, - "type-arg": 1 - }, - "app/modules/indexer/parser/nexus_audiences.py": { - "arg-type": 6, - "assignment": 6, - "no-any-return": 1, - "no-untyped-call": 8, - "no-untyped-def": 34, - "return-value": 1, - "type-arg": 6, - "var-annotated": 1 - }, - "app/modules/indexer/parser/nexus_hhanclub.py": { - "assignment": 1, - "no-untyped-call": 3, - "no-untyped-def": 3 - }, - "app/modules/indexer/parser/nexus_php.py": { - "assignment": 11, - "no-untyped-call": 8, - "no-untyped-def": 10, - "type-arg": 1 - }, - "app/modules/indexer/parser/nexus_project.py": { - "assignment": 3, - "no-untyped-call": 2, - "no-untyped-def": 2 - }, - "app/modules/indexer/parser/nexus_rabbit.py": { - "assignment": 9, - "call-overload": 1, - "no-untyped-call": 1, - "no-untyped-def": 5, - "return": 1, - "type-arg": 1 - }, "app/modules/indexer/parser/rousi.py": { - "assignment": 11, - "no-untyped-def": 8, - "type-arg": 1 - }, - "app/modules/indexer/parser/small_horse.py": { - "assignment": 5, - "no-untyped-call": 3, - "no-untyped-def": 5, - "type-arg": 1 + "no-untyped-def": 2 }, "app/modules/indexer/parser/sunnypt.py": { "arg-type": 2, - "assignment": 9, - "type-arg": 2 - }, - "app/modules/indexer/parser/tnode.py": { - "assignment": 3, - "no-untyped-call": 1, - "no-untyped-def": 6, - "type-arg": 1 - }, - "app/modules/indexer/parser/torrent_leech.py": { - "assignment": 6, - "no-untyped-call": 2, - "type-arg": 1 - }, - "app/modules/indexer/parser/unit3d.py": { - "assignment": 3, - "no-untyped-call": 2, - "no-untyped-def": 5, - "type-arg": 1 - }, - "app/modules/indexer/parser/yema.py": { - "assignment": 12, "type-arg": 1 }, "app/modules/indexer/parser/zhixing.py": { "arg-type": 7, - "assignment": 27, - "empty-body": 1, - "no-untyped-call": 1, - "no-untyped-def": 9, - "type-arg": 1 + "assignment": 7, + "no-untyped-def": 4 }, "app/modules/indexer/spider/__init__.py": { "arg-type": 12,