- Keep ForwardRef._evaluate (recognized by mypy/ty typeshed)
- Fix class _LenientNamespace(dict) -> _LenientNamespace(dict[str, Any])
- Use frozenset() instead of set() for recursive_guard
- Ignore ForwardRef._evaluate deprecation warning in pytest config
- Remove duplicate _resolve_forward_ref_lenient function
- Use ForwardRef.evaluate() instead of deprecated _evaluate()
- Use frozenset() instead of set() for recursive_guard parameter
- Add noqa for E402 in test file (deliberate late import)
Python 3.14 added a new 'type_params' parameter to ForwardRef._evaluate()
(PEP 695). Failing to pass it triggers a DeprecationWarning, which is
treated as error by FastAPI's test suite (-W error). Pass type_params=()
on Python 3.14+ to silence the warning.
In Python 3.13+, ForwardRef._evaluate() requires 'recursive_guard'
as a keyword-only argument. Pass it as keyword to support both
older and newer Python versions.
When using rom __future__ import annotations, annotations are stored as
strings. If Annotated[SomeClass, Depends()] references a class defined
after the route decorator, the forward reference could not be resolved at
decoration time.
FastAPI's evaluate_forwardref() does not raise on unresolvable references
- it returns the raw ForwardRef object. The existing code only handled the
string-to-ForwardRef conversion but did not check whether resolution
actually succeeded, allowing an unresolvable ForwardRef to leak into the
type annotation. This caused Pydantic to fail with
'class-not-fully-defined' errors and the Depends metadata to be lost.
The fix adds a fallback: when evaluate_forwardref() returns a ForwardRef
(rather than the resolved type) and the annotation string is Annotated-
shaped, a lenient resolution evaluates the annotation with a namespace
that maps undefined names to Any. This preserves the Annotated structure
so FastAPI can extract the Depends metadata.
Fix "to to" and "that that" word duplications in security module docstrings,
and "be be" in test data string.
Co-authored-by: ahsan.sheraz <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>