Name collision in google.genai.interactions: triggers.Interaction shadows response model Interaction in static type checkers
Maintainer thường phản hồi trong vòng 1 ngày
@Venkaiahbabuneelam đang làm issue này rồi.
Từ ngày 28/9/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu trong google/genai/interactions.py và kiểm tra các wildcard export từ các module kiểu của triggers và interactions, sau đó tái hiện xung đột bằng lệnh mypy và mã mẫu được cung cấp. Đảm bảo interactions.Interaction được trình kiểm tra kiểu tĩnh phân giải thành response model, giống như nó đã được phân giải khi chạy, và xác nhận rằng các lỗi union-attr được báo cáo đã biến mất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
In google-genai (v2.25.0+), google.genai.interactions exposes types for the Interactions API using wildcard star-imports:
# google/genai/interactions.py (lines 23-32)
# Import triggers before interactions so that interactions.Interaction (the
# resource class) overrides triggers.Interaction (the TypeAliasType representing
# nested interactions inside triggers) in the exported namespace, resolving
# the name collision.
from ._gaos.types.triggers import * # noqa: F401,F403
from ._gaos.types.triggers import __all__ as _triggers_all
from ._gaos.types.environments import * # noqa: F401,F403
from ._gaos.types.environments import __all__ as _environments_all
from ._gaos.types.interactions import * # noqa: F401,F403
from ._gaos.types.interactions import __all__ as _interactions_all
As the comment in google/genai/interactions.py notes, there is a name collision between:
google.genai._gaos.types.triggers.Interaction(TypeAliasType = Union[CreateAgentInteraction, CreateModelInteraction])google.genai._gaos.types.interactions.interaction.Interaction(Pydantic BaseModel representing the interaction response object with.steps,.output_text,.output_image,.output_audio, etc.)
While Python's runtime assigns interactions.Interaction to the later-imported response class, static type checkers (such as mypy with follow_imports = normal) resolve interactions.Interaction to triggers.Interaction (CreateAgentInteraction | CreateModelInteraction).
Steps to Reproduce
Consider the following type-annotated code:
from google.genai import interactions
def inspect_response(interaction: interactions.Interaction) -> None:
if interaction.output_image is not None:
print(interaction.output_image.data)
if interaction.output_audio is not None:
print(interaction.output_audio.data)
if interaction.steps:
print(len(interaction.steps))
Run mypy with follow-imports=normal:
mypy --follow-imports=normal repro.py
Actual Behavior
mypy fails with union-attr errors because it resolves interactions.Interaction to CreateAgentInteraction | CreateModelInteraction:
repro.py:4: error: Item "CreateAgentInteraction" of "CreateAgentInteraction | CreateModelInteraction" has no attribute "output_image" [union-attr]
repro.py:4: error: Item "CreateModelInteraction" of "CreateAgentInteraction | CreateModelInteraction" has no attribute "output_image" [union-attr]
repro.py:6: error: Item "CreateAgentInteraction" of "CreateAgentInteraction | CreateModelInteraction" has no attribute "output_audio" [union-attr]
repro.py:6: error: Item "CreateModelInteraction" of "CreateAgentInteraction | CreateModelInteraction" has no attribute "output_audio" [union-attr]
repro.py:8: error: Item "CreateAgentInteraction" of "CreateAgentInteraction | CreateModelInteraction" has no attribute "steps" [union-attr]
repro.py:8: error: Item "CreateModelInteraction" of "CreateAgentInteraction | CreateModelInteraction" has no attribute "steps" [union-attr]
Expected Behavior
interactions.Interaction should unambiguously resolve to the response model class google.genai._gaos.types.interactions.interaction.Interaction both at runtime and during static type checking.
Workaround
Currently, consumer projects must use a conditional type-checking import workaround:
from typing import TYPE_CHECKING
from google.genai import interactions
if TYPE_CHECKING:
from google.genai._gaos.types.interactions.interaction import Interaction
else:
Interaction = interactions.Interaction
Suggested Solution
In google/genai/interactions.py:
- Avoid wildcard star imports or explicitly re-export the response model after the star imports:
from ._gaos.types.interactions.interaction import Interaction as Interaction - Or rename
triggers.Interactionin_gaos/types/triggerstoTriggerInteraction/InteractionTriggerParamso the names do not collide.
Environment Details
- OS: Linux
- Python: 3.12 / 3.13 / 3.14
- google-genai version: 2.25.0
- mypy version: 1.14+
- Ngôn ngữ chính
- Python
- Star
- 4k
- Fork
- 1k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 88
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/python-genai
-
Test import module that doesn't existCó thể đã có người làm @Venkaiahbabuneelam đã nhận hôm nay. Đang mởpriority: p2 status:awaiting user response type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
googleapis/python-genai#3122 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FunctionDeclaration.from_callable drops enum and properties from Optional[...] parametersCó thể đã có người làm @Venkaiahbabuneelam đã nhận 1 ngày trước. Đang mởpriority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
googleapis/python-genai#3105 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Curated history keeps half a user turn when the model turn is invalidCó thể đã có người làm @Venkaiahbabuneelam đã nhận 9 ngày trước. Đang mởpriority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
googleapis/python-genai#3051 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFCCó thể đã có người làm @Venkaiahbabuneelam đã nhận 9 ngày trước. Đang mởpriority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
googleapis/python-genai#3044 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Live API] Function declaration size degrades speech output (name pronunciation): is there a documented budget or design pattern?Có thể đã có người làm @Venkaiahbabuneelam đã nhận hôm nay. Đang mởpriority: p2 type: bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
googleapis/python-genai#3120 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của googleapis/python-genai
Issue tương tự
-
documentation pkg: sphinx-needs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
useblocks/sphinx-needs#2255 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
home-assistant/core#186538 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
btclib-org/btclib-secp256k1#1181 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pyrite-wiki/pyrite#917 ·
Maintainer thường phản hồi trong vòng 1 ngày