Skip to content

Prepare for typed gRPC stubs from dp-grpc (dp-grpc#158) - #60

Merged
craigmcchesney merged 3 commits into
mainfrom
prep/dp-grpc-158-typed-stubs
Sep 24, 2026
Merged

craigmcchesney merged 3 commits into
mainfrom
prep/dp-grpc-158-typed-stubs

Conversation

@craigmcchesney

@craigmcchesney craigmcchesney commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #61, which tracks both dp-python-lib steps; this is step 1.

Step 1 of the cross-repo sequence in the dp-grpc #158 plan.

Why

dp-grpc is adding mypy-protobuf .pyi stubs to the gRPC package it syncs into src/dp_python_lib/grpc/. Our mypy suppression for that package (exclude plus follow_imports = "skip") does not apply to .pyi files: mypy reads a stub whenever one is present. As a result, the first sync that carries .pyi files would turn CI red. This PR fixes those errors ahead of time, in forms that also pass against today's untyped stubs. It must merge before dp-grpc pushes a rel-* tag that includes the #158 implementation. dp-grpc's release checklist will gate on it.

Changes

  • types-grpcio is added to [dev], and the grpc ignore_missing_imports override is dropped. The override's comment said no stub package existed. This clears the three overload-cannot-match errors in the generated _pb2_grpc.pyi files. It also exposes two errors in mldp_client.py, fixed by declaring the optional query and annotation channels as grpc.Channel | None.
  • machine_config_client.py: an assert narrows the composite activation key after _validate_activation_key. That validator has already guaranteed the values are present, so the assert only informs mypy.
  • export_client.py: ExportFormat.to_proto() is now annotated ExportOutputFormat.ValueType, the enum value type, instead of the enum wrapper class.
  • query_conversions.py: the Image.FileType name map is built from the enum wrapper's items() instead of the Optional enum_type descriptor. I confirmed at runtime that it produces the same map.
  • doc/cookbook/conventions.md: the time snippet rebound t1, which the snippet checker's preamble declares as a datetime. It now uses ts1, ts2, and ts3. The dp-grpc plan did not anticipate this error; it surfaced only when I ran the checker against the typed stubs.
  • [codegen] gains mypy-protobuf>=5.1.0. It matches the version dp-grpc will pin. Its comment names dp-grpc's tools/python-stubs-requirements.in as the authority on versions and generate-python-stubs.yml as the authority on flags.
  • CLAUDE.md and NEXT.md are updated.

The suppression itself stays in place until the synced stubs arrive. Its pyproject.toml comment now also says that it does not hold against .pyi files. Removing it, typing _stub, and adding py.typed belong to the follow-up PR (plan step 5, tracked in #61).

Verification

I generated the stubs locally the same way dp-grpc will: grpcio-tools 1.84.0 plus mypy-protobuf 5.1.0, with --mypy_out / --mypy_grpc_out and the relative-import fixup widened to .pyi. The generated .py files are byte-identical to the ones committed here.

Configuration mypy src/ Cookbook snippets
Current untyped stubs (what CI sees) clean OK
.pyi added, suppression intact (the next sync) clean (was 10 errors) OK (was 1 error)
.pyi added, suppression removed clean* —

* Clean only because ServiceApiClientBase._stub is still Any. Typing it is step 5, and it will surface more errors.

ruff check, ruff format --check, pytest tests/unit (725 passed), and check-release-notes.py also pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01We3Lmjj8XNLK1zpHRr1AwQ

dp-grpc is adding mypy-protobuf .pyi stubs to the synced gRPC package.
The exclude + follow_imports=skip suppression does not hold against .pyi
files, so the first stub-bearing sync would turn CI red with 10 mypy
errors and one cookbook-snippet error.  Fix them ahead of time, in forms
that also pass against today's untyped stubs:

- add types-grpcio to [dev] and drop the grpc ignore_missing_imports
  override; declare MldpClient's optional channels as grpc.Channel | None
- narrow the composite activation key after _validate_activation_key
- ExportFormat.to_proto() returns ExportOutputFormat.ValueType
- build the Image.FileType name map from the enum wrapper's items()
- conventions.md: stop rebinding the checker preamble's t1 handle
- add mypy-protobuf to [codegen]

Plan: osprey-dcs/dp-grpc plan/tickets/158/plan.md (step 1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01We3Lmjj8XNLK1zpHRr1AwQ
Copilot AI lite review requested due to automatic review settings September 24, 2026 22:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Prepares the client library and tooling for upcoming typed gRPC stubs from dp-grpc.

Changes:

  • Adds gRPC typing and mypy-protobuf dependencies.
  • Fixes type-checking issues in client and enum conversion code.
  • Updates documentation, cookbook examples, and release notes.
File Summary
src/​dp_python_lib/​client/​query_conversions.py Uses the typed enum wrapper API.
src/​dp_python_lib/​client/​mldp_client.py Types optional service channels.
src/​dp_python_lib/​client/​machine_config_client.py Narrows validated composite-key values.
src/​dp_python_lib/​client/​export_client.py Corrects protobuf enum return typing.
pyproject.toml Adds typing and stub-generation dependencies.
doc/​release-notes/​NEXT.md Documents the preparation work.
doc/​cookbook/​conventions.md Avoids snippet variable conflicts.
CLAUDE.md Documents typed-stub preparation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

craigmcchesney and others added 2 commits September 24, 2026 16:31
…p in #61

- [codegen] comment: dp-grpc's pins move to tools/python-stubs-requirements.in
  under the #158 plan; the workflow only carries the flags.  Name both.
- [tool.mypy] comment: say that the suppression does not hold against .pyi
  files, where someone editing it will read it, not only in CLAUDE.md.
- CLAUDE.md: rewrap the unwrapped line and cite #61 for the rest of the work.
- NEXT.md: file the section under #61 and word it so it stays true whether or
  not the same release also ships the stubs.

Refs #61

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TquccKRVq9GERyMXRYtfXb
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.

2 participants