Skip to content

Commit

Permalink
chore(internal): fix compat model_dump method when warnings are passed (
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 22, 2024
1 parent c71bba2 commit 0e09236
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/anthropic/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def model_dump(
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
warnings=warnings,
# warnings are not supported in Pydantic v1
warnings=warnings if PYDANTIC_V2 else True,
)
return cast(
"dict[str, Any]",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@ class Model(BaseModel):
m.model_dump(warnings=False)


def test_compat_method_no_error_for_warnings() -> None:
class Model(BaseModel):
foo: Optional[str]

m = Model(foo="hello")
assert isinstance(model_dump(m, warnings=False), dict)


def test_to_json() -> None:
class Model(BaseModel):
foo: Optional[str] = Field(alias="FOO", default=None)
Expand Down

0 comments on commit 0e09236

Please sign in to comment.