-
Notifications
You must be signed in to change notification settings - Fork 698
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
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
- pip install mypy
- mypy script.py
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)Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.