Skip to content

Commit

Permalink
fix mypy typings / use encoders without check because now instances a…
Browse files Browse the repository at this point in the history
…re ensured (#441)

- fix mypy complaining because of only instances and use speedier
  version (it is now ensured that response.encoders are instances)
- reorder check for more speed
  • Loading branch information
devkral authored Nov 26, 2024
1 parent ba4f35a commit 62930fc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions esmerald/responses/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import partial
from inspect import isclass
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -190,7 +189,7 @@ def make_response(self, content: Any) -> Union[bytes, str]:
encoders = (
(
(
*(encoder() if isclass(encoder) else encoder for encoder in self.encoders),
*self.encoders,
*LILYA_ENCODER_TYPES.get(),
)
)
Expand Down
3 changes: 1 addition & 2 deletions esmerald/responses/encoders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import partial
from inspect import isclass
from typing import Any, cast

import orjson
Expand All @@ -24,7 +23,7 @@ def make_response(self, content: Any) -> bytes:
encoders = (
(
(
*(encoder() if isclass(encoder) else encoder for encoder in self.encoders),
*self.encoders,
*LILYA_ENCODER_TYPES.get(),
)
)
Expand Down
3 changes: 2 additions & 1 deletion esmerald/routing/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def convert_annotation_to_pydantic_model(field_annotation: Any) -> Any:

if (
not isinstance(field_annotation, BaseModel)
and any(encoder.is_type(field_annotation) for encoder in LILYA_ENCODER_TYPES.get())
# call before encoder check, because this test is faster
and inspect.isclass(field_annotation)
and any(encoder.is_type(field_annotation) for encoder in LILYA_ENCODER_TYPES.get())
):
field_definitions: Dict[str, Any] = {}

Expand Down
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.11.1",
"lilya>=0.11.2",
"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 62930fc

Please sign in to comment.