|
|
|
@ -1,4 +1,5 @@ |
|
|
|
import re |
|
|
|
import warnings |
|
|
|
from copy import copy, deepcopy |
|
|
|
from dataclasses import dataclass |
|
|
|
from enum import Enum |
|
|
|
@ -82,9 +83,20 @@ class ModelField: |
|
|
|
return self.field_info.annotation |
|
|
|
|
|
|
|
def __post_init__(self) -> None: |
|
|
|
self._type_adapter: TypeAdapter[Any] = TypeAdapter( |
|
|
|
Annotated[self.field_info.annotation, self.field_info] |
|
|
|
) |
|
|
|
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 shared.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(): |
|
|
|
|