Prepare for typed gRPC stubs from dp-grpc (dp-grpc#158) - #60
Merged
Merged
Conversation
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
There was a problem hiding this comment.
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.
…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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TquccKRVq9GERyMXRYtfXb
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.
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
.pyistubs to the gRPC package it syncs intosrc/dp_python_lib/grpc/. Our mypy suppression for that package (excludeplusfollow_imports = "skip") does not apply to.pyifiles: mypy reads a stub whenever one is present. As a result, the first sync that carries.pyifiles 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 arel-*tag that includes the #158 implementation. dp-grpc's release checklist will gate on it.Changes
types-grpciois added to[dev], and thegrpcignore_missing_importsoverride is dropped. The override's comment said no stub package existed. This clears the threeoverload-cannot-matcherrors in the generated_pb2_grpc.pyifiles. It also exposes two errors inmldp_client.py, fixed by declaring the optional query and annotation channels asgrpc.Channel | None.machine_config_client.py: anassertnarrows 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 annotatedExportOutputFormat.ValueType, the enum value type, instead of the enum wrapper class.query_conversions.py: theImage.FileTypename map is built from the enum wrapper'sitems()instead of the Optionalenum_typedescriptor. I confirmed at runtime that it produces the same map.doc/cookbook/conventions.md: the time snippet reboundt1, which the snippet checker's preamble declares as adatetime. It now usests1,ts2, andts3. The dp-grpc plan did not anticipate this error; it surfaced only when I ran the checker against the typed stubs.[codegen]gainsmypy-protobuf>=5.1.0. It matches the version dp-grpc will pin. Its comment names dp-grpc'stools/python-stubs-requirements.inas the authority on versions andgenerate-python-stubs.ymlas the authority on flags.CLAUDE.mdandNEXT.mdare updated.The suppression itself stays in place until the synced stubs arrive. Its
pyproject.tomlcomment now also says that it does not hold against.pyifiles. Removing it, typing_stub, and addingpy.typedbelong 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_outand the relative-import fixup widened to.pyi. The generated.pyfiles are byte-identical to the ones committed here.mypy src/.pyiadded, suppression intact (the next sync).pyiadded, suppression removed* Clean only because
ServiceApiClientBase._stubis stillAny. Typing it is step 5, and it will surface more errors.ruff check,ruff format --check,pytest tests/unit(725 passed), andcheck-release-notes.pyalso pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01We3Lmjj8XNLK1zpHRr1AwQ