Skip to content

2.12.0: mypy resolves google.genai.interactions.Interaction to the triggers TypeAliasType instead of the resource class #2732

Description

@DABH

Environment: google-genai 2.12.0, mypy 1.18.2-2.3.0

Repro:

from google.genai.interactions import Interaction


def check(x: object) -> None:
    if isinstance(x, Interaction):  # error: incompatible type "TypeAliasType"; expected "_ClassInfo"
        print(x.id)                 # error: "object" has no attribute "id"


reveal_type(Interaction)            # note: Revealed type is "typing.TypeAliasType"

When type checking with mypy, we get the errors noted above, while at runtime, the same import binds the resource class, as intended:

>>> from google.genai.interactions import Interaction
>>> Interaction
<class 'google.genai._gaos.types.interactions.interaction.Interaction'>

Cause: google/genai/interactions.py star-imports ._gaos.types.triggers (which exports Interaction as a TypeAliasType) and then ._gaos.types.interactions (the resource class), relying on last-binding-wins. That holds at runtime and for pyright, but mypy keeps the first star-import binding for a redefined name, so typed users get the triggers alias: isinstance is rejected and the resource fields (id, status, …) are missing. Not present in 2.11.x. Downstream example: temporalio/sdk-python#1652.

Potential Fix (verified against an installed 2.12.0): Rename the triggers Interaction alias, or drop it from the star surface merged into interactions. Removing "Interaction" from triggers' __all__ correctly flips mypy to the resource class. An explicit binding inside interactions.py after the star-imports does not help; mypy keeps the alias regardless.

Metadata

Metadata

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions