Skip to content

Commit

Permalink
Linting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschutt authored and provinzkraut committed Jun 27, 2023
1 parent e31b6c7 commit e1b7f8c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions litestar/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import msgspec
from msgspec import ValidationError
from pydantic import (
UUID1,
BaseModel,
ByteSize,
ConstrainedBytes,
ConstrainedDate,
NameEmail,
SecretField,
StrictBool,
UUID1,
)
from pydantic import ValidationError as PydanticValidationError
from pydantic.color import Color
Expand Down Expand Up @@ -134,19 +134,21 @@ def default_serializer(value: Any, type_encoders: Mapping[Any, Callable[[Any], A

def _dec_pydantic_uuid(type_: type[PydanticUUIDType], val: Any) -> PydanticUUIDType:
if isinstance(val, str):
val = UUID(val)
val = type_(val)
elif isinstance(val, (bytes, bytearray)):
try:
val = UUID(val.decode())
val = type_(val.decode())
except ValueError:
# 16 bytes in big-endian order as the bytes argument fail
# the above check
val = UUID(bytes=val.decode())
val = type_(bytes=val)
elif isinstance(val, UUID):
val = type_(str(val))

if not isinstance(val, (UUID, type_)):
if not isinstance(val, type_):
raise ValidationError(f"Invalid UUID: {val!r}")

if type_._required_version != val.version:
if type_._required_version != val.version: # type:ignore[attr-defined]
raise ValidationError(f"Invalid UUID version: {val!r}")

return val
Expand Down

0 comments on commit e1b7f8c

Please sign in to comment.