Skip to content

Conversation

@GeeCastro
Copy link

@GeeCastro GeeCastro commented Dec 16, 2025

The type hint for Content should be Sequence.

When running the examples from the repo with a prompt and an uploaded image, mypy shows a type hint error.

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)

Setting it to slightly more generic Sequence solves the problem.

@google-cla
Copy link

google-cla bot commented Dec 16, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@janasangeetha
Copy link
Collaborator

Hey @GeeCastro
Thanks for contributing!
Please update the branch as it is out-of-date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants