Skip to content

Commit

Permalink
Pydantic V2 support
Browse files Browse the repository at this point in the history
Added Pydantic V2 support
  • Loading branch information
ansenlong authored Sep 18, 2023
1 parent 18a0505 commit 645a527
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion datauri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __get_validators__(cls):
yield cls.validate

@classmethod
def validate(cls, v: str) -> Self:
def validate(cls, v: str, x=None) -> Self:

Check failure on line 163 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / typing (3.7)

Function is missing a type annotation for one

Check failure on line 163 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / typing (3.8)

Function is missing a type annotation for one

Check failure on line 163 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / typing (3.10)

Function is missing a type annotation for one
if not isinstance(v, str):
raise TypeError("string required")

Expand All @@ -169,6 +169,15 @@ def validate(cls, v: str) -> Self:
raise ValueError("invalid data-uri format")
return m

@classmethod
def __get_pydantic_json_schema__(cls, core_schema, handler) -> Dict[str, Any]:

Check failure on line 173 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / typing (3.7)

Function is missing a type annotation for one

Check failure on line 173 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / typing (3.8)

Function is missing a type annotation for one

Check failure on line 173 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / typing (3.10)

Function is missing a type annotation for one
core_schema.update(pattern=DATA_URI_REGEX,
examples=[

Check failure on line 175 in datauri/__init__.py

View workflow job for this annotation

GitHub Actions / flake8

continuation line under-indented for visual indent
"data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu"
],
)
return core_schema

@classmethod
def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None:
# __modify_schema__ should mutate the dict it receives in place,
Expand Down

0 comments on commit 645a527

Please sign in to comment.