googleapis / googleapis/python-genai

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

Open
#2,732 3 comments 1 reaction 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p2 type: bug
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

**Environment:** google-genai 2.12.0, mypy 1.18.2-2.3.0

**Repro:**

```python
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

```

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.