fix(base): cpu_runtime 在非 Linux 主机上的类型检查与测试修复 - #1330
Merged
TATP-233 merged 1 commit intoAug 27, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
os.sched_setaffinity/os.sched_getaffinity是 Linux-only API,typeshed 只在sys.platform == "linux"下声明。macOS 开发机上make test-all失败:make type:src/unilab/base/cpu_runtime.py:49/70: error: Module has no attribute "sched_setaffinity" / "sched_getaffinity" [attr-defined]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/delattr加raising=False,主机有无该属性都能跑;Linux CI 行为不变。Validation
make test-all已完成并通过:mypy 248 files no issues、pyright 通过、2293 passed / 47 skipped、benchmark smoke 36/37(1 个 mlx 平台可选项跳过)。Stacked on #1314.