🎨 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 return annotation
def _try_resolve_annotated_string( def _try_resolve_annotated_string(annotation_str: str, globalns: Dict[str, Any]) -> Any:
annotation_str: str, globalns: Dict[str, Any]
) -> Any:
""" """
Try to partially resolve an Annotated string annotation. 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 to resolve the type part, keep as ForwardRef if it fails
try: try:
resolved_type = evaluate_forwardref( resolved_type = evaluate_forwardref(ForwardRef(type_part), globalns, globalns)
ForwardRef(type_part), globalns, globalns
)
except Exception: except Exception:
resolved_type = ForwardRef(type_part) resolved_type = ForwardRef(type_part)

View File

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