googleapis / googleapis/python-genai

Type hint and mypy on `ContentListUnion` and `ContentListUnionDict`

Aperta
#1,874 1 commento 0 reazioni 1 assegnatario Assegnata a @Venkaiahbabuneelam Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

Mypy complains about the type hint of `types.ContentListUnion` and `types.ContentListUnionDict`. I've managed to get around it with the example in #1873.

#### Environment details

- Programming language: python
- OS: macOS Sequoia 15.5
- Language runtime version: 3.12.11
- Package version: 1.55.0

#### Steps to reproduce

1. pip install mypy
2. mypy script.py

```python
import io
import os
from pathlib import Path

from dotenv import load_dotenv
from google import genai
from google.genai import types
from PIL import Image

load_dotenv()

client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
model = "gemini-2.5-flash-image"

output_path = Path("local_dev") / "image.png"
uploaded_file = client.files.upload(file=output_path, config=types.UploadFileConfig(mime_type="image/png"))
print(f"Uploaded file: {uploaded_file.name}")

prompt = "Add people to the scene"
response = client.models.generate_content(model=model, contents=[uploaded_file, prompt])
# ^^^^^^^^^^^^^^^^^^^^^^^^

Argument "contents" to "generate_content" of "Models" has incompatible type "list[object]"; expected "Content | ContentDict | str | Image | File | FileDict | Part | PartDict | list[str | Image | File | FileDict | Part | PartDict] | list[Content | ContentDict | str | Image | File | FileDict | Part | PartDict | list[str | Image | File | FileDict | Part | PartDict]]"Mypy[arg-type](https://mypy.readthedocs.io/en/latest/_refs.html#code-arg-type)
```

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.