Skip to content

Commit

Permalink
Update to Lilya 0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Nov 25, 2024
1 parent a18a242 commit 2dba64d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions esmerald/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from typing import Any, TypeVar, get_args

import msgspec
from lilya._internal._encoders import json_encoder as json_encoder # noqa
from lilya._utils import is_class_and_subclass
from lilya.encoders import (
ENCODER_TYPES as ENCODER_TYPES, # noqa
Encoder as LilyaEncoder, # noqa
json_encode as json_encode, # noqa
register_encoder as register_encoder, # noqa
)
from msgspec import Struct
Expand Down Expand Up @@ -36,7 +36,7 @@ def serialize(self, obj: Any) -> Any:
"""
raise NotImplementedError("All Esmerald encoders must implement serialize() method.")

def encode(self, annotation: Any, value: Any) -> Any:
def encode(self, structure: Any, value: Any) -> Any:
"""
Function that transforms the kwargs into a structure
"""
Expand All @@ -55,8 +55,8 @@ def serialize(self, obj: Any) -> Any:
"""
return msgspec.json.decode(msgspec.json.encode(obj))

def encode(self, annotation: Any, value: Any) -> Any:
return msgspec.json.decode(msgspec.json.encode(value), type=annotation)
def encode(self, structure: Any, value: Any) -> Any:
return msgspec.json.decode(msgspec.json.encode(value), type=structure)


class PydanticEncoder(Encoder):
Expand All @@ -70,10 +70,10 @@ def serialize(self, obj: BaseModel) -> dict[str, Any]:
except PydanticSerializationError:
return obj.model_dump()

def encode(self, annotation: Any, value: Any) -> Any:
def encode(self, structure: Any, value: Any) -> Any:
if isinstance(value, BaseModel) or is_class_and_subclass(value, BaseModel):
return value
return annotation(**value)
return structure(**value)


def register_esmerald_encoder(encoder: Encoder[Any]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions esmerald/responses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from orjson import OPT_OMIT_MICROSECONDS, OPT_SERIALIZE_NUMPY, dumps
from typing_extensions import Annotated, Doc

from esmerald.encoders import Encoder, json_encoder
from esmerald.encoders import Encoder, json_encode
from esmerald.enums import MediaType
from esmerald.exceptions import ImproperlyConfigured

Expand Down Expand Up @@ -180,7 +180,7 @@ def transform(value: Any) -> Dict[str, Any]:
Supports all the default encoders from Lilya and custom from Esmerald.
"""
return cast(Dict[str, Any], json_encoder(value))
return cast(Dict[str, Any], json_encode(value))

def make_response(self, content: Any) -> Union[bytes, str]:
try:
Expand Down
4 changes: 2 additions & 2 deletions esmerald/responses/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from lilya.responses import JSONResponse

from esmerald.encoders import json_encoder
from esmerald.encoders import json_encode


class BaseJSONResponse(JSONResponse):
Expand All @@ -16,7 +16,7 @@ def transform(value: Any) -> Dict[str, Any]: # pragma: no cover
Makes sure that every value is checked and if it's a pydantic model then parses into
a dict().
"""
return cast(Dict[str, Any], json_encoder(value))
return cast(Dict[str, Any], json_encode(value))


__all__ = ["BaseJSONResponse"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
"email-validator >=2.2.0,<3.0.0",
"itsdangerous>=2.1.2,<3.0.0",
"jinja2>=3.1.2,<4.0.0",
"lilya>=0.10.0",
"lilya>=0.11.0",
"loguru>=0.7.0,<0.8.0",
"pydantic>=2.9.1,<3.0.0",
"pydantic-settings>=2.0.0,<3.0.0",
Expand Down

0 comments on commit 2dba64d

Please sign in to comment.