Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/deepgram/core/pydantic_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def construct(cls: Type["Model"], _fields_set: Optional[Set[str]] = None, **valu
return super().construct(_fields_set, **dealiased_object)

def json(self, **kwargs: Any) -> str:
kwargs_with_defaults = {
"by_alias": True,
"exclude_unset": True,
**kwargs,
}
# Precompute kwargs_with_defaults only once, minimizing dict merging overhead
if not kwargs:
kwargs_with_defaults = {"by_alias": True, "exclude_unset": True}
else:
# Avoid unnecessary dict merging when kwargs is empty
kwargs_with_defaults = dict(by_alias=True, exclude_unset=True, **kwargs)
if IS_PYDANTIC_V2:
return super().model_dump_json(**kwargs_with_defaults) # type: ignore[misc]
return super().json(**kwargs_with_defaults)
Expand Down