Fix type checking for google-genai 2.12.0#1652
Open
DABH wants to merge 3 commits into
Open
Conversation
google-genai 2.12.0 exports two Interaction names from google.genai.interactions: the interaction resource class and a TypeAliasType over the trigger-request variants. Runtime star-import ordering deliberately binds the name to the resource class, but type checkers resolve it to the alias, which cannot be used with isinstance and lacks the resource fields — mypy fails with 34 errors (first seen on test-latest-deps when 2.12.0 released). Add a _compat shim that keeps the runtime binding on the public path (the imported object is unchanged — identity-verified against 2.10.0 and 2.12.0) and points the static view at the class's defining module, which is the same location in both versions. Redirect the three import sites through the shim. Verified with mypy, pyright, and basedpyright plus the google_genai test suite (62 passed) under both google-genai 2.10.0 (locked) and 2.12.0 (latest).
Contributor
Author
|
Upstream issue filed: googleapis/python-genai#2732 (tracks the export collision; when it's fixed, |
brianstrauch
approved these changes
Jul 16, 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.
What
google-genai2.12.0 (released 2026-07-16, within our>=2.10.0,<3.0.0range) broke type checking oftemporalio.contrib.google_genai:test-latest-depsfails with 34 mypy errors (isinstancewith aTypeAliasType, missingid/statusattributes). Every branch's nexttest-latest-depsrun fails the same way.Why
2.12.0's
google.genai.interactionsexports twoInteractionnames: the interaction resource class and aTypeAliasTypeover the trigger-request variants (CreateAgentInteraction | CreateModelInteraction). The module deliberately orders its star-imports so the resource class wins at runtime (per the comment in that module), but type checkers resolve the name to the alias, which fails (doesn't work withisinstance, no resource fields).How
A new
_compat.pyshim:google.genai.interactions.Interaction(verified the imported object is identical under 2.10.0 and 2.12.0, so there is no functionality change);TYPE_CHECKING): binds the class' defining module, which is the same location in 2.10.x and 2.12.0.The three import sites (
_gemini_activity,_temporal_interactions,test_gemini) go through the shim. Remove the shim once upstream exports the resource class unambiguously for type checkers.Verification
All tests and CI checks pass now with 2.10 and 2.12