Skip to content

DeprecationWarning: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17 #1640

Closed

Description

@ilvez

Environment details

  • Programming language: Python
  • OS: Linux 6.17.6+deb14-amd64
  • Language runtime version: Python 3.14.0
  • Package version: google-genai version: 1.49.0

Steps to reproduce

  1. Run the script: python test_genai_deprecation.py
  2. Observe deprecation warning:
/home/ilvez/.local/share/mise/installs/python/3.14.0/lib/python3.14/site-packages/google/genai/types.py:43: DeprecationWarning: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17
  VersionedUnionType = Union[builtin_types.UnionType, _UnionGenericAlias]

The script:

"""
Issue: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17
Location: google/genai/types.py:43

To reproduce:
1. Install: pip install google-genai==1.49.0
2. Run: python -W default test_genai_deprecation.py

Expected output: DeprecationWarning about '_UnionGenericAlias'
"""

import warnings

# Enable all warnings to ensure DeprecationWarning is shown
warnings.filterwarnings('default', category=DeprecationWarning)

# Simply importing google.genai triggers the deprecation warning
import google.genai  # noqa: F401

print("Import successful. Check above for DeprecationWarning.")
print(f"Python version: {__import__('sys').version}")
print(f"google-genai version: {google.genai.__version__}")

Example of running with 3.13 and 3.14:

% python test_genai_deprecation.py
Import successful. Check above for DeprecationWarning.
Python version: 3.13.8 (main, Oct 10 2025, 12:48:21) [Clang 20.1.4 ]
google-genai version: 1.49.0

% mise use -g [email protected]
mise ~/.config/mise/config.toml tools: [email protected]

% python test_genai_deprecation.py
/home/ilvez/.local/share/mise/installs/python/3.14.0/lib/python3.14/site-packages/google/genai/types.py:43: DeprecationWarning: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17
  VersionedUnionType = Union[builtin_types.UnionType, _UnionGenericAlias]
Import successful. Check above for DeprecationWarning.
Python version: 3.14.0 (main, Oct 31 2025, 23:03:06) [Clang 21.1.4 ]
google-genai version: 1.49.0

Activity

  1. added
    type: bug
    priority: p2
    on Nov 7, 2025
  2. ilvez commented on Nov 7, 2025

    @ilvez
    Author

    Not really sure it's something to solve at all (related to how the solution would look like with older Pythons etc..), but just wanted to mark it down so if there's an resolution to this, then at least it's documented.

  3. janasangeetha commented on Dec 2, 2025

    @janasangeetha

    Hey @ilvez
    Thank you for bringing this to our attention. We truly appreciate you flagging this issue, we will file a bug internally.

  4. sakshamgoyal-01 commented on Jul 6, 2026

    @sakshamgoyal-01

    still waiting on an update on this. It's been months.
    python 3.9 is already EOL so you can safely remove that snippet to check python version >=3.10.
    the requires-python is already set to >=3.10 so it's completely unnecessary to keep now.

    if the sdk generator is available on github, I can make a PR for it since the file mentions:

    # Code generated by the Google Gen AI SDK generator DO NOT EDIT.
  5. janisto commented on Jul 14, 2026

    @janisto

    This is still present in google-genai==2.11.0 on Python 3.14.6.

    My Firebase Functions application uses genkit==0.7.0 together with genkit-plugin-google-genai==0.7.0. Importing the Vertex AI plugin:

    from genkit.plugins.google_genai import VertexAI

    transitively imports google.genai, which triggers this warning during pytest collection:

    DeprecationWarning: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17
    

    It is annoying that downstream projects treating warnings as errors must add an exception for an upstream import warning:

    [tool.pytest.ini_options]
    testpaths = ["tests"]
    filterwarnings = [
        "error",
        'ignore::DeprecationWarning:google\.genai\.types',
    ]

    I do not have a preference for the internal implementation. However, importing a supported package version on Python 3.14 should not emit a deprecation warning for reliance on a private Python API scheduled for removal in Python 3.17.

  6. eyb1 commented on Jul 18, 2026

    @eyb1

    FTR, The latest version as of today (google-genai 2.12.1) still produces the same warning.

  7. acoustesh commented on Oct 12, 2026

    @acoustesh

    Still reproducible with google-genai 2.29.0 on Python 3.14.6:

    google/genai/types.py:42: DeprecationWarning: '_UnionGenericAlias' is deprecated and slated for removal in Python 3.17
      VersionedUnionType = Union[builtin_types.UnionType, _UnionGenericAlias]
    

    The warning is triggered by the private import on types.py line 28 (from typing import ..., _UnionGenericAlias # type: ignore) and its use on line 42.

    Possible fix: build the alias from public objects instead of the private name:

    VersionedUnionType = Union[builtin_types.UnionType, type(Union[int, str])]

    Alternatively, drop the alias and use the _UNION_TYPES = (typing.Union, builtin_types.UnionType) tuple already defined on the next line, with typing.get_origin(x) in _UNION_TYPES for the isinstance checks.

    The same private name is also used in:

    • google/genai/_extra_utils.py:42 (UnionType = typing._UnionGenericAlias)
    • google/genai/_automatic_function_calling_util.py:31 (VersionedUnionType = typing._UnionGenericAlias)

    so those should be updated together.

  8. ilvez commented on Oct 23, 2026

    @ilvez
    Author

    Wow, just noticed that it's nearly a year open now :-D Birthday soon! 🎂

  9. ilvez commented on Oct 29, 2026

    @ilvez
    Author

    Oh I jinxed it. No birthday, it seems #3194 solved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: p2type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions