import dataclasses
import inspect
+import sys
from contextlib import AsyncExitStack, contextmanager
from copy import copy, deepcopy
from dataclasses import dataclass
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
- signature = inspect.signature(call)
+ if sys.version_info >= (3, 10):
+ signature = inspect.signature(call, eval_str=True)
+ else:
+ signature = inspect.signature(call)
unwrapped = inspect.unwrap(call)
globalns = getattr(unwrapped, "__globals__", {})
typed_params = [
def get_typed_return_annotation(call: Callable[..., Any]) -> Any:
- signature = inspect.signature(call)
+ if sys.version_info >= (3, 10):
+ signature = inspect.signature(call, eval_str=True)
+ else:
+ signature = inspect.signature(call)
unwrapped = inspect.unwrap(call)
annotation = signature.return_annotation
--- /dev/null
+from __future__ import annotations
+
+from fastapi import Depends, FastAPI, Request
+from fastapi.testclient import TestClient
+from typing_extensions import Annotated
+
+from .utils import needs_py310
+
+
+class Dep:
+ def __call__(self, request: Request):
+ return "test"
+
+
+@needs_py310
+def test_stringified_annotations():
+ app = FastAPI()
+
+ client = TestClient(app)
+
+ @app.get("/test/")
+ def call(test: Annotated[str, Depends(Dep())]):
+ return {"test": test}
+
+ response = client.get("/test")
+ assert response.status_code == 200