Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- use eval_str for newer pythons

Note: still crashes because of the NamedTupleEncoder
  • Loading branch information
devkral committed Nov 26, 2024
1 parent fc26c94 commit 81bc6d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/en/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ hide:

- Per stack encoders.
- Leverage new lilya encoder API. Encoders can use `__type__`
- **Breaking** for custom Encoders implementing encode either `__type__` or `is_type_structure` must be provided.
- **Breaking** For custom Encoders implementing encode either `__type__` or `is_type_structure` must be provided.
- **Breaking** For Python >=3.10 eval_str is used for retrieving the annotations of a function. The results can be slightly different.

## 3.5.0

Expand Down
7 changes: 6 additions & 1 deletion esmerald/transformers/signature.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import sys
from inspect import Parameter as InspectParameter, Signature as InspectSignature
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -41,6 +42,10 @@

object_setattr = object.__setattr__

_signature_kwargs: dict = {}
if sys.version_info >= (3, 10):
_signature_kwargs["eval_str"] = True


def is_server_error(error: Any, klass: Type["SignatureModel"]) -> bool:
"""
Expand Down Expand Up @@ -350,7 +355,7 @@ def __init__(self, fn: "AnyCallable", dependency_names: Set[str], **kwargs: Any)
"""
super().__init__(**kwargs)
self.fn = fn
self.signature = InspectSignature.from_callable(self.fn)
self.signature = InspectSignature.from_callable(self.fn, **_signature_kwargs)
self.fn_name = fn.__name__ if hasattr(fn, "__name__") else "anonymous"
self.defaults: Dict[str, Any] = {}
self.dependency_names = dependency_names
Expand Down
8 changes: 2 additions & 6 deletions tests/dependencies/test_simple_case_injected_annotation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from typing import TYPE_CHECKING, List
from typing import List

from esmerald import post
from esmerald.injector import Inject
from esmerald.routing.apis.views import APIView
from esmerald.routing.gateways import Gateway
from esmerald.testclient import create_client
from tests.dependencies.samples import DocumentService

if TYPE_CHECKING:
from tests.dependencies.samples import DocumentCreateDTO
from tests.dependencies.samples import DocumentCreateDTO, DocumentService


class DocumentAPIView(APIView):
Expand All @@ -25,7 +22,6 @@ async def create(


def test_injection():

with create_client(routes=[Gateway(handler=DocumentAPIView)]) as client:
response = client.post("/", json={"name": "test", "content": "test"})
assert response.status_code == 201
Expand Down

0 comments on commit 81bc6d7

Please sign in to comment.