11
11
from abc import ABCMeta
12
12
from functools import lru_cache , partial
13
13
from types import FunctionType
14
- from typing import Any , Callable , ForwardRef , Generic , Literal , NoReturn
14
+ from typing import Any , Callable , Generic , Literal , NoReturn
15
15
16
16
import typing_extensions
17
17
from pydantic_core import PydanticUndefined , SchemaSerializer
30
30
from ._schema_generation_shared import CallbackGetCoreSchemaHandler
31
31
from ._signature import generate_pydantic_signature
32
32
from ._typing_extra import (
33
+ _make_forward_ref ,
33
34
eval_type_backport ,
34
35
is_annotated ,
35
36
is_classvar ,
@@ -436,6 +437,8 @@ def inspect_namespace( # noqa C901
436
437
is_valid_privateattr_name (ann_name )
437
438
and ann_name not in private_attributes
438
439
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`:
439
442
and not is_classvar (ann_type )
440
443
and ann_type not in all_ignored_types
441
444
and getattr (ann_type , '__module__' , None ) != 'functools'
@@ -446,7 +449,9 @@ def inspect_namespace( # noqa C901
446
449
frame = sys ._getframe (2 )
447
450
if frame is not None :
448
451
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 ,
450
455
)
451
456
if is_annotated (ann_type ):
452
457
_ , * metadata = typing_extensions .get_args (ann_type )
0 commit comments