[chore]: Move from inspect.siganture to model_fields.items() in get_all_basemodel_annotations

This commit is contained in:
keenborder786 2025-04-27 04:03:58 +05:00
parent 7fe753436e
commit 979b81864e

View File

@ -1078,7 +1078,7 @@ def get_all_basemodel_annotations(
# cls has no subscript: cls = FooBar
if isinstance(cls, type):
annotations: dict[str, type] = {}
for name, param in inspect.signature(cls).parameters.items():
for name, param in cls.model_fields.items():
# Exclude hidden init args added by pydantic Config. For example if
# BaseModel(extra="allow") then "extra_data" will part of init sig.
if (
@ -1094,7 +1094,6 @@ def get_all_basemodel_annotations(
get_origin(cls), default_to_bound=False
)
orig_bases = (cls,)
# Pydantic v2 automatically resolves inherited generics, Pydantic v1 does not.
if not (isinstance(cls, type) and is_pydantic_v2_subclass(cls)):
# if cls = FooBar inherits from Baz[str], orig_bases will contain Baz[str]