Commit Graph

2 Commits

Author SHA1 Message Date
ahsan.sheraz fff2b10e04 Fix pre-commit formatting and test coverage
- Collapse _try_resolve_annotated signature to one line (ruff format)
- Add pragma: no cover to dep() stubs that are never called during tests

Made-with: Cursor
2026-03-11 16:11:54 +01:00
ahsan.sheraz e00b071435 Fix Annotated with ForwardRef when using `from __future__ import annotations`
When `from __future__ import annotations` is active, annotations become
strings.  If a type referenced inside `Annotated[T, Depends(...)]` is
defined after the route decorator, `T` is not yet available at decoration
time and the full `Annotated` string cannot be resolved.  FastAPI then
loses the `Depends` metadata and incorrectly treats the parameter as a
query parameter.

The fix introduces a lenient evaluation strategy: when strict evaluation
of the annotation string fails, a `_LenientDict` namespace is used where
undefined names resolve to `Any`.  This preserves the `Annotated`
structure and allows FastAPI to extract `Depends` metadata.  The lenient
result is only accepted when it contains `Depends` metadata — for other
metadata types (Query, Body, etc.) the actual type is needed, so the
existing fallback behaviour is kept.

Fixes #13056

Made-with: Cursor
2026-03-11 16:01:13 +01:00