Repository: tiangolo/fastapi
File: fastapi/_compat.py (Python)

Code before:
        name: str
        mode: Literal["validation", "serialization"] = "validation"

        @property
        def alias(self) -> str:
            a = self.field_info.alias
            return a if a is not None else self.name

        @property
        def required(self) -> bool:
            return self.field_info.is_required()

        @property
        def default(self) -> Any:
            return self.get_default()

        @property
        def type_(self) -> Any:
            return self.field_info.annotation

        def __post_init__(self) -> None:
            with warnings.catch_warnings():
                # Pydantic >= 2.12.0a1 warns about this when building
                # TypeAdapters from field information that uses aliases.
                # The Pydantic team recommends ignoring this in this case:
                # https://github.com/fastapi/fastapi/pull/14036#issuecomment-3316045587
                try:
                    from pydantic.warnings import (  # type: ignore[attr-defined]
                        UnsupportedFieldAttributeWarning,
                    )
                except ImportError:  # pragma: no cover
                    pass
                else:  # pragma: no cover
                    warnings.simplefilter(
                        "ignore", category=UnsupportedFieldAttributeWarning
                    )
                self._type_adapter: TypeAdapter[Any] = TypeAdapter(
                    Annotated[self.field_info.annotation, self.field_info]
                )

        def get_default(self) -> Any:
            if self.field_info.is_required():
                return Undefined
            return self.field_info.get_default(call_default_factory=True)

        def validate(
            self,
            value: Any,
            values: Dict[str, Any] = {},  # noqa: B006
            *,
            loc: Tuple[Union[int, str], ...] = (),

Review comment (suggestion):
```suggestion
                # Pydantic >= 2.12.0 warns about field specific metadata that is unused
                # (e.g. `TypeAdapter(Annotated[int, Field(alias='b')])`). In some cases, we
                # end up building the type adapter from a model field annotation so we
                # need to ignore the warning:

Code after:
        name: str
        mode: Literal["validation", "serialization"] = "validation"

        @property
        def alias(self) -> str:
            a = self.field_info.alias
            return a if a is not None else self.name

        @property
        def required(self) -> bool:
            return self.field_info.is_required()

        @property
        def default(self) -> Any:
            return self.get_default()

        @property
        def type_(self) -> Any:
            return self.field_info.annotation

        def __post_init__(self) -> None:
            with warnings.catch_warnings():
                # Pydantic >= 2.12.0 warns about field specific metadata that is unused
                # (e.g. `TypeAdapter(Annotated[int, Field(alias='b')])`). In some cases, we
                # end up building the type adapter from a model field annotation so we
                # need to ignore the warning:
                if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 12):
                    from pydantic.warnings import UnsupportedFieldAttributeWarning

                    warnings.simplefilter(
                        "ignore", category=UnsupportedFieldAttributeWarning
                    )
                self._type_adapter: TypeAdapter[Any] = TypeAdapter(
                    Annotated[self.field_info.annotation, self.field_info]
                )

        def get_default(self) -> Any:
            if self.field_info.is_required():
                return Undefined
            return self.field_info.get_default(call_default_factory=True)

        def validate(
            self,
            value: Any,
            values: Dict[str, Any] = {},  # noqa: B006
            *,
            loc: Tuple[Union[int, str], ...] = (),
        ) -> Tuple[Any, Union[List[Dict[str, Any]], None]]:
            try:
                return (
                    self._type_adapter.validate_python(value, from_attributes=True),