1111from abc import ABCMeta
1212from functools import lru_cache , partial
1313from types import FunctionType
14- from typing import Any , Callable , ForwardRef , Generic , Literal , NoReturn
14+ from typing import Any , Callable , Generic , Literal , NoReturn
1515
1616import typing_extensions
1717from pydantic_core import PydanticUndefined , SchemaSerializer
3030from ._schema_generation_shared import CallbackGetCoreSchemaHandler
3131from ._signature import generate_pydantic_signature
3232from ._typing_extra import (
33+ _make_forward_ref ,
3334 eval_type_backport ,
3435 is_annotated ,
3536 is_classvar ,
@@ -436,6 +437,8 @@ def inspect_namespace( # noqa C901
436437 is_valid_privateattr_name (ann_name )
437438 and ann_name not in private_attributes
438439 and ann_name not in ignored_names
440+ # This condition is a false negative when `ann_type` is stringified,
441+ # but it is handled in `set_model_fields`:
439442 and not is_classvar (ann_type )
440443 and ann_type not in all_ignored_types
441444 and getattr (ann_type , '__module__' , None ) != 'functools'
@@ -446,7 +449,9 @@ def inspect_namespace( # noqa C901
446449 frame = sys ._getframe (2 )
447450 if frame is not None :
448451 ann_type = eval_type_backport (
449- ForwardRef (ann_type ), globalns = frame .f_globals , localns = frame .f_locals
452+ _make_forward_ref (ann_type , is_argument = False , is_class = True ),
453+ globalns = frame .f_globals ,
454+ localns = frame .f_locals ,
450455 )
451456 if is_annotated (ann_type ):
452457 _ , * metadata = typing_extensions .get_args (ann_type )
0 commit comments