This commit is contained in:
keenborder786 2025-04-27 04:56:30 +05:00
parent c888ea409c
commit 63a3a28a1c
2 changed files with 8 additions and 3 deletions

View File

@ -1082,8 +1082,9 @@ def get_all_basemodel_annotations(
for name, param in cls.model_fields.items():
if param.alias and param.alias != name:
warnings.warn(
f"Field '{name}' has alias '{param.alias}'. The alias will be used in tool schema instead of the field name.",
stacklevel=2
f"Field '{name}' has alias '{param.alias}'. The alias will be\
used in tool schema instead of the field name.",
stacklevel=2,
)
for name, param in inspect.signature(cls).parameters.items():
# Exclude hidden init args added by pydantic Config. For example if

View File

@ -2709,5 +2709,9 @@ def test_get_all_basemodel_annotations_warning() -> None:
class ModelWithAlias(BaseModel):
field_with_alias: str = Field(alias="alias_field")
with pytest.warns(UserWarning, match="Field 'field_with_alias' has alias 'alias_field'. The alias will be used in tool schema instead of the field name."):
with pytest.warns(
UserWarning,
match="Field 'field_with_alias' has alias 'alias_field'. The alias will be\
used in tool schema instead of the field name.",
):
get_all_basemodel_annotations(ModelWithAlias)