Skip to content

fix(base): cpu_runtime 在非 Linux 主机上的类型检查与测试修复 - #1330

Merged
TATP-233 merged 1 commit into
dev/issue-1304-motion-numba-body-statefrom
fix/cpu-runtime-darwin-mypy
Aug 27, 2026
Merged

fix(base): cpu_runtime 在非 Linux 主机上的类型检查与测试修复#1330
TATP-233 merged 1 commit into
dev/issue-1304-motion-numba-body-statefrom
fix/cpu-runtime-darwin-mypy

Conversation

@TATP-233

Copy link
Copy Markdown
Collaborator

问题

os.sched_setaffinity / os.sched_getaffinity 是 Linux-only API,typeshed 只在 sys.platform == "linux" 下声明。macOS 开发机上 make test-all 失败:

  1. make typesrc/unilab/base/cpu_runtime.py:49/70: error: Module has no attribute "sched_setaffinity" / "sched_getaffinity" [attr-defined]
  2. 修复 mypy 后 pytest tests/base/test_cpu_runtime.py 接着失败:monkeypatch.setattr/delattr 默认 raising=True,而 macOS 上 os 根本没有这两个属性。

修复

  • src/unilab/base/cpu_runtime.py:改为在调用点通过 getattr(os, "sched_setaffinity", None) 解析符号(运行时语义与 hasattr 完全一致,仍可在测试中 monkeypatch;不绑定到 import 期)。
  • tests/base/test_cpu_runtime.py:相关 monkeypatch.setattr/delattrraising=False,主机有无该属性都能跑;Linux CI 行为不变。

Validation

  • 本地 make test-all 已完成并通过:mypy 248 files no issues、pyright 通过、2293 passed / 47 skipped、benchmark smoke 36/37(1 个 mlx 平台可选项跳过)。
  • 按用户要求跳过远程 CI 等待。

Stacked on #1314.

os.sched_setaffinity/sched_getaffinity are Linux-only, so mypy on darwin
rejected the direct attribute access (attr-defined) and the unit tests'
monkeypatch.setattr/delattr failed because the attributes do not exist.

Resolve the affinity symbols via getattr at call time (identical runtime
semantics, still monkeypatchable) and pass raising=False to the test
monkeypatch seams so they work whether or not the host exposes them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant