757 B
757 B
paths
| paths | |
|---|---|
|
Use msgspec.Struct, not @dataclass
Define data containers as msgspec.Struct. Do not add new
dataclasses.dataclass (or attrs) — they weaken strict type checking and
don't translate cleanly for multi-language support (e.g. the planned Rust migration).
import msgspec
class LoadSnapshot(msgspec.Struct): # prefer frozen= and omit_defaults=; kw_only= as needed
dp_rank: int = 0
tokens: list[int] = [] # mutable defaults are safe
- Methods /
@classmethodconstructors go on theStruct; seepython/sglang/srt/managers/load_snapshot.py. - New code only. Existing
@dataclassis grandfathered — migrate opportunistically while editing the file, not in drive-by sweeps.