Skip to content

feat: parsed candidate can be a list#886

Open
Vandivier wants to merge 5 commits intogoogleapis:mainfrom
Vandivier:882-let-me-list-bro
Open

feat: parsed candidate can be a list#886
Vandivier wants to merge 5 commits intogoogleapis:mainfrom
Vandivier:882-let-me-list-bro

Conversation

@Vandivier
Copy link

closes #882

this code functionally works as of 1.16.1, and mypy accepts it:

        if (
            response
            and hasattr(response, "parsed")
            and response.parsed is not None
        ):
            parsed_items = cast(list[XcomTableAnalysisResult], response.parsed)
            logger.info(f"Response preview: {parsed_items[0]}")
            return parsed_items

but, I don't want to cast. Casting reduces my confidence in my unit tests.

I'm really uncomfortable at unit test time, where I need response.parsed to be mocked with a type not officially supported in the library.

So, to avoid casting, let's explicitly support the list[pydantic.BaseModel]!

@Vandivier
Copy link
Author

@sararob @MarkDaoust thoughts?

@MarkDaoust
Copy link
Collaborator

MarkDaoust commented Jun 18, 2025

Thanks for the ping.

list, yes, but list[pydantic.BaseModel] is too restrictive. Basically it could be any json compatible object (with pydantic-Objects). Would list[Any] work?

@janasangeetha janasangeetha self-assigned this Nov 7, 2025
@Vandivier
Copy link
Author

@MarkDaoust updated!

@janasangeetha
Copy link
Collaborator

@Vandivier
The branch seems out-of-date. Please update the same.

@Vandivier
Copy link
Author

@janasangeetha done!

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.

GenerateContentResponse.parsed type should support list[pydantic.BaseModel]

3 participants