Skip to content

Commit be8cd49

Browse files
wanlin31copybara-github
authored andcommitted
chore: internal change
PiperOrigin-RevId: 885180110
1 parent 2856c0a commit be8cd49

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

google/genai/_interactions/_compat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
1919
from datetime import date, datetime
20-
from typing_extensions import Self, Literal
20+
from typing_extensions import Self, Literal, TypedDict
2121

2222
import pydantic
2323
from pydantic.fields import FieldInfo
@@ -146,6 +146,10 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
146146
return model.model_dump_json(indent=indent)
147147

148148

149+
class _ModelDumpKwargs(TypedDict, total=False):
150+
by_alias: bool
151+
152+
149153
def model_dump(
150154
model: pydantic.BaseModel,
151155
*,
@@ -157,14 +161,17 @@ def model_dump(
157161
by_alias: bool | None = None,
158162
) -> dict[str, Any]:
159163
if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
164+
kwargs: _ModelDumpKwargs = {}
165+
if by_alias is not None:
166+
kwargs["by_alias"] = by_alias
160167
return model.model_dump(
161168
mode=mode,
162169
exclude=exclude,
163170
exclude_unset=exclude_unset,
164171
exclude_defaults=exclude_defaults,
165172
# warnings are not supported in Pydantic v1
166173
warnings=True if PYDANTIC_V1 else warnings,
167-
by_alias=by_alias,
174+
**kwargs,
168175
)
169176
return cast(
170177
"dict[str, Any]",

0 commit comments

Comments
 (0)