fix: Remove deprecated _UnionGenericAlias to support Python 3.14+#1939
Open
miettal wants to merge 4 commits intogoogleapis:mainfrom
Open
fix: Remove deprecated _UnionGenericAlias to support Python 3.14+#1939miettal wants to merge 4 commits intogoogleapis:mainfrom
miettal wants to merge 4 commits intogoogleapis:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Replace usage of private typing._UnionGenericAlias (deprecated in Python 3.14, removed in 3.17) with tuple-based isinstance checks using type(Union[int, str]). This maintains compatibility with both old-style Union[T1, T2] and new-style T1 | T2 syntax while avoiding deprecation warnings.
Collaborator
|
Hey @miettal |
Author
|
I sync the branch. ( if rebase is needed, I will re-make branch) |
Collaborator
|
Kindly fix the failing check |
Fixes ImportError caused by passing a tuple to Union[]. The previous commit (e290f46) changed VersionedUnionType from a Union type to a tuple for isinstance checks, but SchemaUnion was still trying to use it as a Union argument. This expands the tuple elements individually for Python 3.10+ (UnionType + _UnionGenericAlias) and Python < 3.10 (_UnionGenericAlias only). Error: TypeError: Union[arg, ...]: each arg must be a type. Got (<class 'types.UnionType'>, <class 'typing._UnionGenericAlias'>).
Resolves mypy errors by adding TypeAlias annotations and using TYPE_CHECKING to separate type-checking time definitions from runtime definitions. This ensures mypy recognizes SchemaUnion as a valid type alias while maintaining runtime compatibility across Python versions. Fixes mypy errors: - "Invalid type alias: expression is not a valid type" - "Variable 'genai.types.SchemaUnion' is not valid as a type"
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 deprecation warnings in Python 3.14 by removing usage of private
typing._UnionGenericAliasAPI.Changes
_UnionGenericAliaswith tuple-basedisinstance()checks usingtype(Union[int, str])types.py,_transformers.py,_automatic_function_calling_util.pyUnion[T1, T2]andT1 | T2syntaxBackground
_UnionGenericAliasis a private API deprecated in Python 3.14 and scheduled for removal in Python 3.17. The new approach avoids private APIs while maintaining identical functionality for runtime type checking.Testing
🤖 Generated with Claude Code