🎨 Auto format

This commit is contained in:
pre-commit-ci-lite[bot] 2025-12-17 16:28:11 +00:00 committed by GitHub
parent 9e7ca4d454
commit a975a1704e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 16 deletions

View File

@ -305,9 +305,7 @@ def get_typed_annotation(annotation: Any, globalns: Dict[str, Any]) -> Any:
return annotation
def _try_resolve_annotated_string(
annotation_str: str, globalns: Dict[str, Any]
) -> Any:
def _try_resolve_annotated_string(annotation_str: str, globalns: Dict[str, Any]) -> Any:
"""
Try to partially resolve an Annotated string annotation.
@ -347,9 +345,7 @@ def _try_resolve_annotated_string(
# Try to resolve the type part, keep as ForwardRef if it fails
try:
resolved_type = evaluate_forwardref(
ForwardRef(type_part), globalns, globalns
)
resolved_type = evaluate_forwardref(ForwardRef(type_part), globalns, globalns)
except Exception:
resolved_type = ForwardRef(type_part)

View File

@ -1,4 +1,5 @@
"""Test case for issue #13056: Can't use `Annotated` with `ForwardRef`"""
from __future__ import annotations
from dataclasses import dataclass
@ -11,12 +12,12 @@ app = FastAPI()
def get_potato() -> Potato:
return Potato(color='red', size=10)
return Potato(color="red", size=10)
@app.get('/')
@app.get("/")
async def read_root(potato: Annotated[Potato, Depends(get_potato)]):
return {'color': potato.color, 'size': potato.size}
return {"color": potato.color, "size": potato.size}
@dataclass
@ -30,24 +31,26 @@ client = TestClient(app)
def test_annotated_forward_ref():
"""Test that forward references work correctly with Annotated dependencies."""
response = client.get('/')
response = client.get("/")
assert response.status_code == 200
data = response.json()
assert data == {'color': 'red', 'size': 10}
assert data == {"color": "red", "size": 10}
def test_openapi_schema():
"""Test that OpenAPI schema is generated correctly."""
response = client.get('/openapi.json')
response = client.get("/openapi.json")
assert response.status_code == 200
schema = response.json()
# The root path should NOT have query parameters for potato
# It should only be a dependency
root_path = schema['paths']['/']['get']
root_path = schema["paths"]["/"]["get"]
# Check that potato is not a query parameter
parameters = root_path.get('parameters', [])
potato_params = [p for p in parameters if 'potato' in p.get('name', '').lower()]
assert len(potato_params) == 0, f"Potato should not appear as a query parameter: {potato_params}"
parameters = root_path.get("parameters", [])
potato_params = [p for p in parameters if "potato" in p.get("name", "").lower()]
assert len(potato_params) == 0, (
f"Potato should not appear as a query parameter: {potato_params}"
)
if __name__ == "__main__":