Skip to content

Commit

Permalink
Update ENCODER_TYPES to read from context var
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Nov 25, 2024
1 parent 2dba64d commit 0c54751
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions esmerald/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import msgspec
from lilya._utils import is_class_and_subclass
from lilya.encoders import (
ENCODER_TYPES as ENCODER_TYPES, # noqa
ENCODER_TYPES as LILYA_ENCODER_TYPES, # noqa
Encoder as LilyaEncoder, # noqa
json_encode as json_encode, # noqa
register_encoder as register_encoder, # noqa
Expand All @@ -19,9 +19,10 @@

T = TypeVar("T")

ENCODER_TYPES = LILYA_ENCODER_TYPES.get()

class Encoder(LilyaEncoder[T]):

class Encoder(LilyaEncoder[T]):
def is_type(self, value: Any) -> bool:
"""
Function that checks if the function is
Expand All @@ -44,7 +45,6 @@ def encode(self, structure: Any, value: Any) -> Any:


class MsgSpecEncoder(Encoder):

def is_type(self, value: Any) -> bool:
return isinstance(value, Struct) or is_class_and_subclass(value, Struct)

Expand All @@ -60,7 +60,6 @@ def encode(self, structure: Any, value: Any) -> Any:


class PydanticEncoder(Encoder):

def is_type(self, value: Any) -> bool:
return isinstance(value, BaseModel) or is_class_and_subclass(value, BaseModel)

Expand Down

0 comments on commit 0c54751

Please sign in to comment.