Skip to content

Commit

Permalink
fix(types): allow arbitrary types in image block param (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jul 10, 2024
1 parent 601dd30 commit 43998fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/anthropic/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,14 @@ def validate_type(*, type_: type[_T], value: object) -> _T:
return cast(_T, _validate_non_model_type(type_=type_, value=value))


def set_pydantic_config(typ: Any, config: pydantic.ConfigDict) -> None:
"""Add a pydantic config for the given type.
Note: this is a no-op on Pydantic v1.
"""
setattr(typ, "__pydantic_config__", config) # noqa: B010


# our use of subclasssing here causes weirdness for type checkers,
# so we just pretend that we don't subclass
if TYPE_CHECKING:
Expand Down
4 changes: 4 additions & 0 deletions src/anthropic/types/image_block_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .._types import Base64FileInput
from .._utils import PropertyInfo
from .._models import set_pydantic_config

__all__ = ["ImageBlockParam", "Source"]

Expand All @@ -19,6 +20,9 @@ class Source(TypedDict, total=False):
type: Required[Literal["base64"]]


set_pydantic_config(Source, {"arbitrary_types_allowed": True})


class ImageBlockParam(TypedDict, total=False):
source: Required[Source]

Expand Down

0 comments on commit 43998fc

Please sign in to comment.