Repository navigation
Conversation
… | v6 union Static checkers cannot evaluate the runtime protobuf-version gate, so they kept both import arms live and typed every proto symbol as a v5 | v6 union. Because the SDK's public API is annotated with these types, the union spread into downstream code (45 spurious invalid-argument-type diagnostics under ty in pydantic-ai's xai model). Add a TYPE_CHECKING arm that imports the v6 modules; the elif chain that runs at runtime is unchanged. Fixes xai-org#177.
This was referenced Oct 20, 2026
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.
Summary
Fixes #177.
src/xai_sdk/proto/__init__.pychooses.v5or.v6at runtime fromgoogle.protobuf.__version__. Type checkers cannot evaluate that gate, so they keep both arms live and type every re-exported*_pb2symbol asv5.X | v6.X. Because the SDK's public API is annotated with these types, the union spreads into every consumer; @dsfaccini measured 45 spuriousinvalid-argument-typediagnostics undertyin pydantic-ai's xai model from this alone, and it cannot be fixed from the consumer side.This adds an
if TYPE_CHECKING:arm that imports the.v6modules and turns the runtimeifintoelif. The v5 and v6 generated modules expose the same classes, so pinning one arm for typing is accurate. Runtime behaviour is unchanged: theelifchain is what executes.The change is the one proposed in #177; opening it as a PR so it can be reviewed, with credit to @dsfaccini for the analysis.
Verification
from xai_sdk.proto import chat_pb2resolves toxai_sdk.proto.v6.chat_pb2on protobuf 6.31.1, as before.tyon a 6-line probe (passchat_pb2.FormatType.FORMAT_TYPE_JSON_OBJECTto a parameter typedv6.chat_pb2.FormatType):invalid-argument-typeonmain, clean with this change.ruff check .andruff format --checkclean;pytest: 861 passed.== 6comparison to>= 6; this change does not touch that line).