googleapis / googleapis/python-genai

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

Aperta
#2,732 3 commenti 1 reazione 1 assegnatario Rivendicata da @Venkaiahbabuneelam Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.