You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type: clean mypy in optracing, quant, serve, session, sysinfo, telemetry, utils and enforce in CI (#916)
@
## Summary
Brings seven more `winml.modelkit` packages to **zero mypy errors**
under the strict `[tool.mypy]` config and wires them into the required
CI type-check gate (16 → 23 packages). Continues the incremental cleanup
from #896.
Cleaned: **optracing, quant, serve, session, sysinfo, telemetry, utils**
(sysinfo was already clean). Fixes follow the repos typing playbook —
fix at the source first; `cast()` only at genuine untyped third-party
boundaries; `Any` only for true dynamic pass-throughs.
## Real bugs surfaced (not just typing)
- **`utils/hub_utils.py` version import** — `from ..version import
__version__` referenced a non-existent module; guarded by `try/except`,
so the export version was silently always `"unknown"`. Fixed to `from ..
import __version__`. (The containing helper `inject_hub_metadata` is
dead code — tracked in #913.)
- **`utils/hub_utils.py`** — `model_info.modelId` → `model_info.id`
(huggingface_hub renamed the attribute).
## Notable fixes
- **session** — bound a non-None local after auto-compile so narrowing
survives into the lambda/comprehension; explicit guards for `resolved_ep
is None` and single-mode `model_path`; widened PDH counter containers to
`float`; class-level `_initialized` annotation; distinct ctypes struct
locals.
- **telemetry** — annotated the `LoggerProvider`/`Logger` instance
attributes (were inferred as `None`, cascading into
unreachable/attr-defined); OTel/JSON boundary casts; typed the
`@contextmanager`/`@asynccontextmanager` generators.
- **serve** — `cast()` at `json.loads`/`app.state` boundaries; `import
binascii` to use `binascii.Error` (typeshed doesnt expose
`base64.binascii`); explicit single-mode `model_path` guard.
- **utils** — removed stale `# type: ignore`s; `DataclassInstance` cast
for generic-`TypeVar` dataclass reflection; `EPAlias` key cast for the
alias lookup; loop-variable rename to fix
`InputTensorSpec`/`OutputTensorSpec` shadowing.
## Config changes (`pyproject.toml`)
- **`qairt.*`** → `ignore_missing_imports` (external Qualcomm AI Runtime
SDK; imported only inside `compile_qairt_bin.py`, which runs in a
separate `venv-winml` subprocess — absent from the CI env).
- **`windowsml`** → `follow_untyped_imports = true` (installed but ships
no `py.typed`; analyzing its source is clean and keeps its inline
annotations instead of collapsing to `Any`).
## Verification
- Combined required-gate invocation (all 23 packages): `Success: no
issues found in 300 source files`.
- ruff clean; unit tests green for the touched packages (2 pre-existing
OpenVINO-EP-unavailable failures in this env, confirmed unrelated).
- Branch-vs-main diff is content-only (line endings normalized to LF to
match main).
@
---------
Co-authored-by: Hualiang Xie <hualxie@microsoft.com>
0 commit comments