Skip to content

type: clean mypy in optracing, quant, serve, session, sysinfo, telemetry, utils and enforce in CI#916

Merged
xieofxie merged 7 commits into
mainfrom
hualxie/type_5
Jun 22, 2026
Merged

type: clean mypy in optracing, quant, serve, session, sysinfo, telemetry, utils and enforce in CI#916
xieofxie merged 7 commits into
mainfrom
hualxie/type_5

Conversation

@xieofxie

Copy link
Copy Markdown
Contributor

@

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 importfrom ..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 Clean up unused inject_hub_metadata in utils/hub_utils.py #913.)
  • utils/hub_utils.pymodel_info.modelIdmodel_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.
  • servecast() 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: ignores; 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).
  • windowsmlfollow_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).
    @

@xieofxie xieofxie requested a review from a team as a code owner June 18, 2026 06:22
Comment thread src/winml/modelkit/utils/config_utils.py Dismissed
Comment thread src/winml/modelkit/telemetry/library/exporter.py Outdated
Comment thread src/winml/modelkit/utils/data_utils.py Outdated
Comment thread src/winml/modelkit/session/monitor/_pdh.py Outdated
Comment thread src/winml/modelkit/session/session.py
Comment thread src/winml/modelkit/serve/cli_api.py Outdated
Hualiang Xie and others added 2 commits June 22, 2026 14:00
- exporter: None-check timestamp instead of 'or' (timestamp=0 is valid epoch)
- cli_api: drop None from the json.loads cast (bracket-matched -> dict|list only)
- data_utils: widen expected to Mapping[str, Sequence[int|str|None]] (covariant, no caller cascade); remove unreachable ignore
- _pdh: keep running-time ns counters as int (float64 loses precision past 2**53), convert at assignment
- session: add onnx_path/device to the InferenceError context

@DingmaomaoBJTU DingmaomaoBJTU left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All five findings from the previous round are addressed in f2091a2:

  • Bug fixed: �xporter.py timestamp now uses explicit is not None guard — epoch=0 is handled correctly.
  • Warning fixed: data_utils.py signature widened to Mapping[str, Sequence[int | str | None]]; # type: ignore[unreachable] removed.
  • Warning fixed: _pdh.py running-time counters reverted to dict[str, int] with explicit int() at assignment; delta computation is now clean.
  • Info addressed: session.py InferenceError context now includes onnx_path and device.
  • Info addressed: cli_api.py cast no longer includes None in the union type.

LGTM.

@xieofxie xieofxie merged commit 6bd2a0a into main Jun 22, 2026
9 checks passed
@xieofxie xieofxie deleted the hualxie/type_5 branch June 22, 2026 06:51
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.

3 participants