From 97ce5de0bf309ea0c096088247c06545c7400bf6 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Thu, 12 Mar 2026 22:35:11 +0100 Subject: [PATCH] make mypy happy --- fastapi/_compat/v2.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fastapi/_compat/v2.py b/fastapi/_compat/v2.py index 11b17b9fa0..6cf5c67f7c 100644 --- a/fastapi/_compat/v2.py +++ b/fastapi/_compat/v2.py @@ -1,6 +1,6 @@ import re import warnings -from collections.abc import Sequence +from collections.abc import Callable, Sequence from copy import copy from dataclasses import dataclass, is_dataclass from enum import Enum @@ -39,11 +39,16 @@ from pydantic_core.core_schema import ( RequiredParam = PydanticUndefined Undefined = PydanticUndefined -# eval_type_lenient has been deprecated since Pydantic v2.10.0b1 (PR #10530) -evaluate_forwardref = getattr(_pydantic_typing_extra, "try_eval_type", None) -if evaluate_forwardref is None: - evaluate_forwardref = _pydantic_typing_extra.eval_type_lenient -assert evaluate_forwardref is not None + +def define_forwardref() -> Callable[..., Any]: + # eval_type_lenient has been deprecated since Pydantic v2.10.0b1 (PR #10530) + eval_type = getattr(_pydantic_typing_extra, "try_eval_type", None) + if eval_type is not None: + return cast(Callable[..., Any], eval_type) + return _pydantic_typing_extra.eval_type_lenient + + +evaluate_forwardref = define_forwardref() class GenerateJsonSchema(_GenerateJsonSchema):