diff --git a/fastapi/_compat/v2.py b/fastapi/_compat/v2.py index 89340fcf39..a980f55879 100644 --- a/fastapi/_compat/v2.py +++ b/fastapi/_compat/v2.py @@ -1,6 +1,6 @@ import re import warnings -from collections.abc import Callable, Sequence +from collections.abc import Sequence from copy import copy from dataclasses import dataclass, is_dataclass from enum import Enum @@ -40,17 +40,18 @@ RequiredParam = PydanticUndefined Undefined = PydanticUndefined -def define_forwardref() -> Callable[..., Any]: +def evaluate_forwardref( + value: Any, + globalns: dict[str, Any] | None = None, + localns: dict[str, Any] | None = None, +) -> Any: # eval_type_lenient has been deprecated since Pydantic v2.10.0b1 (PR #10530) try_eval_type = getattr(_pydantic_typing_extra, "try_eval_type", None) if try_eval_type is not None: - return lambda *args: try_eval_type(*args)[0] - return ( - _pydantic_typing_extra.eval_type_lenient - ) # pragma: no cover # ty: ignore[deprecated] - - -evaluate_forwardref = define_forwardref() + return try_eval_type(value, globalns, localns)[0] + return _pydantic_typing_extra.eval_type_lenient( # ty: ignore[deprecated] + value, globalns, localns + ) # pragma: no cover class GenerateJsonSchema(_GenerateJsonSchema):