Browse Source

Merge 9413db6bd9 into 1d434dec47

pull/11355/merge
chaen 5 days ago
committed by GitHub
parent
commit
0a439b8cb1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      fastapi/dependencies/utils.py
  2. 0
      tests/test_future/__init__.py
  3. 10
      tests/test_future/login_tool.py
  4. 31
      tests/test_future/test_future_6465.py
  5. 26
      tests/test_future/test_future_9095.py

7
fastapi/dependencies/utils.py

@ -1,4 +1,5 @@
import inspect
import sys
from contextlib import AsyncExitStack, contextmanager
from copy import copy, deepcopy
from dataclasses import dataclass
@ -229,6 +230,9 @@ def get_flat_params(dependant: Dependant) -> List[ModelField]:
def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
if sys.version_info >= (3, 10):
signature = inspect.signature(call, eval_str=True)
else:
signature = inspect.signature(call)
globalns = getattr(call, "__globals__", {})
typed_params = [
@ -252,6 +256,9 @@ def get_typed_annotation(annotation: Any, globalns: Dict[str, Any]) -> Any:
def get_typed_return_annotation(call: Callable[..., Any]) -> Any:
if sys.version_info >= (3, 10):
signature = inspect.signature(call, eval_str=True)
else:
signature = inspect.signature(call)
annotation = signature.return_annotation

0
tests/test_future/__init__.py

10
tests/test_future/login_tool.py

@ -0,0 +1,10 @@
from functools import wraps
def login_required(func):
@wraps(func)
def wrapper(*args, **kwargs):
# login functionality could come here
return func(*args, **kwargs)
return wrapper

31
tests/test_future/test_future_6465.py

@ -0,0 +1,31 @@
from __future__ import annotations
from typing import Optional
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
from ..utils import needs_py310
from .login_tool import login_required
app = FastAPI()
client = TestClient(app)
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
@needs_py310
def test_future_6465():
@app.get("/items/")
@login_required
def get_item(item_id: int) -> Item:
return Item(name="name", price=42.42)
res = client.get("/items?item_id=3")
assert res.status_code == 200

26
tests/test_future/test_future_9095.py

@ -0,0 +1,26 @@
from __future__ import annotations
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from starlette.requests import Request
from ..utils import needs_py310
app = FastAPI()
client = TestClient(app)
class Test:
def __call__(self, request: Request):
return "test"
@needs_py310
def test_call():
@app.get("/test/")
def call(test: str = Depends(Test())):
return {"test": test}
response = client.get("/test")
assert response.status_code == 200
Loading…
Cancel
Save