o
    i_|                     @  sj  U d Z ddlmZ ddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZ d	d
lmZmZmZ d	dlm Z  d	dl!m"Z" d	dl#m$Z$ d	dlm%Z%m&Z& ej'dk rwddlm(Z( nddlm(Z( ej)Z*ej+dfddiej,G dd dZ-ej+dfddiej,G dd dZ.ej+dfddiej,G dd dZ/ej+dfddiej,G dd dZ0er)G dd de(Z1G dd de(Z2G dd  d e(Z3G d!d" d"e(Z4ee2ej5e1ej6f Z7ee4ej8e3ej9f Z:ee;eeef e<eef ee f Z=d#e>d$< ed%ee7e=f d&Z?ed'ee:e=f d&Z@ed( ZAd#e>d)< ed*d*d+dgd7d8ZBed*d*d+dhd;d8ZBed*d*d<did>d8ZBd?ded@djdBd8ZBedCZCedDddEZDG dFdG dGejEe(eD ZFG dHdI dIe(eC ZGG dJdK dKe(eC ZHG dLdM dMe(ZIG dNdO dOe(ZJG dPdQ dQe(ZKG dRdS dSe(ZLeeCgeCf ZM	 eeCejNe geCf ZO	 eeHeC eGeC f ZPeeKeLeIeJf ZQeeOeC eMeC f ZRedkdUdVZSedldYdVZSedmd[dVZSdnd]dVZSed^ZTereeTd*f ZUnej+dfi ej,G d_d` d`ZUereeTd*f ZVnej+dfi ej,G dadb dbZVedcZWG ddde deZXdS )ozBThis module contains related classes and functions for validation.    )annotationsN)partialmethod)FunctionType)	TYPE_CHECKING	AnnotatedAnyCallableLiteralTypeVarUnioncastoverload)PydanticUndefinedcore_schema)Self	TypeAlias   )_decorators	_generics_internal_dataclass)GetCoreSchemaHandler)PydanticUserError)version_short)ArbitraryTypeWarningPydanticDeprecatedSince212)      )ProtocolfrozenTc                   @  s2   e Zd ZU dZded< dd
dZedddZdS )AfterValidatoraT  !!! abstract "Usage Documentation"
        [field *after* validators](../concepts/validators.md#field-after-validator)

    A metadata class that indicates that a validation should be applied **after** the inner validation logic.

    Attributes:
        func: The validator function.

    Example:
        ```python
        from typing import Annotated

        from pydantic import AfterValidator, BaseModel, ValidationError

        MyInt = Annotated[int, AfterValidator(lambda v: v + 1)]

        class Model(BaseModel):
            a: MyInt

        print(Model(a=1).a)
        #> 2

        try:
            Model(a='a')
        except ValidationError as e:
            print(e.json(indent=2))
            '''
            [
              {
                "type": "int_parsing",
                "loc": [
                  "a"
                ],
                "msg": "Input should be a valid integer, unable to parse string as an integer",
                "input": "a",
                "url": "https://errors.pydantic.dev/2/v/int_parsing"
              }
            ]
            '''
        ```
    Kcore_schema.NoInfoValidatorFunction | core_schema.WithInfoValidatorFunctionfuncsource_typer   handlerr   returncore_schema.CoreSchemac                 C  sT   ||}t | jddd}|rttj| j}tj||dS ttj| j}tj||dS )Nafterfieldmodetypeschema)_inspect_validatorr!   r   r   WithInfoValidatorFunctionZ"with_info_after_validator_functionNoInfoValidatorFunction no_info_after_validator_function)selfr"   r#   r,   info_argr!    r3   X/home/kim/smarthome/.venv/lib/python3.10/site-packages/pydantic/functional_validators.py__get_pydantic_core_schema__K   s   z+AfterValidator.__get_pydantic_core_schema__	decorator>_decorators.Decorator[_decorators.FieldValidatorDecoratorInfo]r   c                 C  s   | |j dS )Nr!   r8   clsr6   r3   r3   r4   _from_decoratorU   s   zAfterValidator._from_decoratorNr"   r   r#   r   r$   r%   r6   r7   r$   r   )__name__
__module____qualname____doc____annotations__r5   classmethodr;   r3   r3   r3   r4   r      s   
 *

r   c                   @  >   e Zd ZU dZded< eZded< dddZedddZ	dS )BeforeValidatora  !!! abstract "Usage Documentation"
        [field *before* validators](../concepts/validators.md#field-before-validator)

    A metadata class that indicates that a validation should be applied **before** the inner validation logic.

    Attributes:
        func: The validator function.
        json_schema_input_type: The input type used to generate the appropriate
            JSON Schema (in validation mode). The actual input type is `Any`.

    Example:
        ```python
        from typing import Annotated

        from pydantic import BaseModel, BeforeValidator

        MyInt = Annotated[int, BeforeValidator(lambda v: v + 1)]

        class Model(BaseModel):
            a: MyInt

        print(Model(a=1).a)
        #> 2

        try:
            Model(a='a')
        except TypeError as e:
            print(e)
            #> can only concatenate str (not "int") to str
        ```
    r    r!   r   json_schema_input_typer"   r#   r   r$   r%   c                 C  r   ||}| j tu rd n|| j }t| jddd}|r*ttj| j}tj|||dS ttj	| j}tj
|||dS )Nbeforer'   r(   r,   json_schema_input_schema)rF   r   generate_schemar-   r!   r   r   r.   Z#with_info_before_validator_functionr/   Z!no_info_before_validator_functionr1   r"   r#   r,   input_schemar2   r!   r3   r3   r4   r5      s"   

z,BeforeValidator.__get_pydantic_core_schema__r6   r7   r   c                 C     | |j |jjdS N)r!   rF   r!   inforF   r9   r3   r3   r4   r;         zBeforeValidator._from_decoratorNr<   r=   
r>   r?   r@   rA   rB   r   rF   r5   rC   r;   r3   r3   r3   r4   rE   Z   s   
  
rE   c                   @  rD   )PlainValidatora  !!! abstract "Usage Documentation"
        [field *plain* validators](../concepts/validators.md#field-plain-validator)

    A metadata class that indicates that a validation should be applied **instead** of the inner validation logic.

    !!! note
        Before v2.9, `PlainValidator` wasn't always compatible with JSON Schema generation for `mode='validation'`.
        You can now use the `json_schema_input_type` argument to specify the input type of the function
        to be used in the JSON schema when `mode='validation'` (the default). See the example below for more details.

    Attributes:
        func: The validator function.
        json_schema_input_type: The input type used to generate the appropriate
            JSON Schema (in validation mode). The actual input type is `Any`.

    Example:
        ```python
        from typing import Annotated, Union

        from pydantic import BaseModel, PlainValidator

        def validate(v: object) -> int:
            if not isinstance(v, (int, str)):
                raise ValueError(f'Expected int or str, go {type(v)}')

            return int(v) + 1

        MyInt = Annotated[
            int,
            PlainValidator(validate, json_schema_input_type=Union[str, int]),  # (1)!
        ]

        class Model(BaseModel):
            a: MyInt

        print(Model(a='1').a)
        #> 2

        print(Model(a=1).a)
        #> 2
        ```

        1. In this example, we've specified the `json_schema_input_type` as `Union[str, int]` which indicates to the JSON schema
        generator that in validation mode, the input type for the `a` field can be either a [`str`][] or an [`int`][].
    r    r!   r   rF   r"   r#   r   r$   r%   c           	   	   C  s   ddl m} z||}|dtjdd |||d}W n |y(   d }Y nw || j}t| jddd	}|rHt	tj
| j}tj|||d
S t	tj| j}tj|||d
S )Nr   PydanticSchemaGenerationErrorserializationc                 S     || S Nr3   vhr3   r3   r4   <lambda>       z=PlainValidator.__get_pydantic_core_schema__.<locals>.<lambda>)functionr,   Zreturn_schemaplainr'   r(   )rW   rJ   )pydanticrV   getr   #wrap_serializer_function_ser_schemarK   rF   r-   r!   r   r.   Z"with_info_plain_validator_functionr/   Z no_info_plain_validator_function)	r1   r"   r#   rV   r,   rW   rM   r2   r!   r3   r3   r4   r5      s:   z+PlainValidator.__get_pydantic_core_schema__r6   r7   r   c                 C  rN   rO   rP   r9   r3   r3   r4   r;      rR   zPlainValidator._from_decoratorNr<   r=   )
r>   r?   r@   rA   rB   r   rF   r5   rC   r;   r3   r3   r3   r4   rT      s   
 .
)rT   c                   @  rD   )WrapValidatora  !!! abstract "Usage Documentation"
        [field *wrap* validators](../concepts/validators.md#field-wrap-validator)

    A metadata class that indicates that a validation should be applied **around** the inner validation logic.

    Attributes:
        func: The validator function.
        json_schema_input_type: The input type used to generate the appropriate
            JSON Schema (in validation mode). The actual input type is `Any`.

    ```python
    from datetime import datetime
    from typing import Annotated

    from pydantic import BaseModel, ValidationError, WrapValidator

    def validate_timestamp(v, handler):
        if v == 'now':
            # we don't want to bother with further validation, just return the new value
            return datetime.now()
        try:
            return handler(v)
        except ValidationError:
            # validation failed, in this case we want to return a default value
            return datetime(2000, 1, 1)

    MyTimestamp = Annotated[datetime, WrapValidator(validate_timestamp)]

    class Model(BaseModel):
        a: MyTimestamp

    print(Model(a='now').a)
    #> 2032-01-02 03:04:05.000006
    print(Model(a='invalid').a)
    #> 2000-01-01 00:00:00
    ```
    zScore_schema.NoInfoWrapValidatorFunction | core_schema.WithInfoWrapValidatorFunctionr!   r   rF   r"   r#   r   r$   r%   c                 C  rG   )Nwrapr'   r(   rI   )rF   r   rK   r-   r!   r   r   WithInfoWrapValidatorFunctionZ!with_info_wrap_validator_functionNoInfoWrapValidatorFunctionZno_info_wrap_validator_functionrL   r3   r3   r4   r5   ,  s&   

z*WrapValidator.__get_pydantic_core_schema__r6   r7   r   c                 C  rN   rO   rP   r9   r3   r3   r4   r;   D  rR   zWrapValidator._from_decoratorNr<   r=   rS   r3   r3   r3   r4   rd     s   
 &
rd   c                   @  s   e Zd ZdddZdS )	_OnlyValueValidatorClsMethodr:   r   valuer$   c                C     d S rY   r3   r1   r:   ri   r3   r3   r4   __call__O      z%_OnlyValueValidatorClsMethod.__call__Nr:   r   ri   r   r$   r   r>   r?   r@   rl   r3   r3   r3   r4   rh   N      rh   c                   @     e Zd Zd
ddZd	S )_V2ValidatorClsMethodr:   r   ri   rQ   core_schema.ValidationInfo[Any]r$   c                C  rj   rY   r3   r1   r:   ri   rQ   r3   r3   r4   rl   R  rm   z_V2ValidatorClsMethod.__call__Nr:   r   ri   r   rQ   rs   r$   r   ro   r3   r3   r3   r4   rr   Q  rp   rr   c                   @  rq   ) _OnlyValueWrapValidatorClsMethodr:   r   ri   r#   (core_schema.ValidatorFunctionWrapHandlerr$   c                C  rj   rY   r3   r1   r:   ri   r#   r3   r3   r4   rl   U  rm   z)_OnlyValueWrapValidatorClsMethod.__call__N)r:   r   ri   r   r#   rw   r$   r   ro   r3   r3   r3   r4   rv   T  rp   rv   c                   @  s   e Zd Zdd	d
ZdS )_V2WrapValidatorClsMethodr:   r   ri   r#   rw   rQ   rs   r$   c                C  rj   rY   r3   r1   r:   ri   r#   rQ   r3   r3   r4   rl   X     z"_V2WrapValidatorClsMethod.__call__N)
r:   r   ri   r   r#   rw   rQ   rs   r$   r   ro   r3   r3   r3   r4   ry   W  rp   ry   r   _PartialClsOrStaticMethod"_V2BeforeAfterOrPlainValidatorType)bound_V2WrapValidatorType)rH   r&   re   r`   FieldValidatorModes.)check_fieldsrF   r'   strfieldsr)   Literal['wrap']r   bool | NonerF   r   r$   6Callable[[_V2WrapValidatorType], _V2WrapValidatorType]c               G  rj   rY   r3   r'   r)   r   rF   r   r3   r3   r4   field_validatorz     r   Literal['before', 'plain']RCallable[[_V2BeforeAfterOrPlainValidatorType], _V2BeforeAfterOrPlainValidatorType]c               G  rj   rY   r3   r   r3   r3   r4   r     r   )r)   r   Literal['after']c               G  rj   rY   r3   )r'   r)   r   r   r3   r3   r4   r     r{   r&   )r)   r   rF   Callable[[Any], Any]c                 s   t | trtddddvrturtdddtu r&dkr&t| gR tdd	 D s;td
ddd fdd}|S )aO  !!! abstract "Usage Documentation"
        [field validators](../concepts/validators.md#field-validators)

    Decorate methods on the class indicating that they should be used to validate fields.

    Example usage:
    ```python
    from typing import Any

    from pydantic import (
        BaseModel,
        ValidationError,
        field_validator,
    )

    class Model(BaseModel):
        a: str

        @field_validator('a')
        @classmethod
        def ensure_foobar(cls, v: Any):
            if 'foobar' not in v:
                raise ValueError('"foobar" not found in a')
            return v

    print(repr(Model(a='this is foobar good')))
    #> Model(a='this is foobar good')

    try:
        Model(a='snap')
    except ValidationError as exc_info:
        print(exc_info)
        '''
        1 validation error for Model
        a
          Value error, "foobar" not found in a [type=value_error, input_value='snap', input_type=str]
        '''
    ```

    For more in depth examples, see [Field Validators](../concepts/validators.md#field-validators).

    Args:
        field: The first field the `field_validator` should be called on; this is separate
            from `fields` to ensure an error is raised if you don't pass at least one.
        *fields: Additional field(s) the `field_validator` should be called on.
        mode: Specifies whether to validate the fields before or after validation.
        check_fields: Whether to check that the fields actually exist on the model.
        json_schema_input_type: The input type of the function. This is only used to generate
            the appropriate JSON Schema (in validation mode) and can only specified
            when `mode` is either `'before'`, `'plain'` or `'wrap'`.

    Returns:
        A decorator that can be used to decorate a function to be used as a field_validator.

    Raises:
        PydanticUserError:
            - If `@field_validator` is used bare (with no fields).
            - If the args passed to `@field_validator` as fields are not strings.
            - If `@field_validator` applied to instance methods.
    z`@field_validator` should be used with fields and keyword arguments, not bare. E.g. usage should be `@validator('<field_name>', ...)`zvalidator-no-fieldscode)rH   r`   re   z;`json_schema_input_type` can't be used when mode is set to zvalidator-input-typer`   c                 s  s    | ]}t |tV  qd S rY   )
isinstancer   ).0r'   r3   r3   r4   	<genexpr>  s    z"field_validator.<locals>.<genexpr>z`@field_validator` fields should be passed as separate string args. E.g. usage should be `@validator('<field_name_1>', '<field_name_2>', ...)`zvalidator-invalid-fieldsfHCallable[..., Any] | staticmethod[Any, Any] | classmethod[Any, Any, Any]r$   (_decorators.PydanticDescriptorProxy[Any]c                   s>   t | rtdddt | } t j d}t | |S )Nz8`@field_validator` cannot be applied to instance methodszvalidator-instance-methodr   )r   r)   r   rF   )r   Zis_instance_method_from_sigr   %ensure_classmethod_based_on_signatureZFieldValidatorDecoratorInfoPydanticDescriptorProxyr   Zdec_infor   r   rF   r)   r3   r4   dec  s   

zfield_validator.<locals>.decN)r   r   r$   r   )r   r   r   r   r   all)r'   r)   r   rF   r   r   r3   r   r4   r     s(   
D
_ModelType_ModelTypeCo)	covariantc                   @  s   e Zd ZdZ	ddd	d
ZdS )ModelWrapValidatorHandlerz]`@model_validator` decorated function handler argument type. This is used when `mode='wrap'`.Nri   r   outer_locationstr | int | Noner$   r   c                C  rj   rY   r3   )r1   ri   r   r3   r3   r4   rl        z"ModelWrapValidatorHandler.__call__rY   )ri   r   r   r   r$   r   r>   r?   r@   rA   rl   r3   r3   r3   r4   r     s    r   c                   @  s   e Zd ZdZdd
dZdS )ModelWrapValidatorWithoutInfozA `@model_validator` decorated function signature.
    This is used when `mode='wrap'` and the function does not have info argument.
    r:   type[_ModelType]ri   r   r#   %ModelWrapValidatorHandler[_ModelType]r$   r   c                C  rj   rY   r3   rx   r3   r3   r4   rl        	z&ModelWrapValidatorWithoutInfo.__call__N)r:   r   ri   r   r#   r   r$   r   r   r3   r3   r3   r4   r         r   c                   @  s   e Zd ZdZdddZdS )ModelWrapValidatorzSA `@model_validator` decorated function signature. This is used when `mode='wrap'`.r:   r   ri   r   r#   r   rQ   core_schema.ValidationInfor$   r   c                C  rj   rY   r3   rz   r3   r3   r4   rl   -  s   
zModelWrapValidator.__call__N)
r:   r   ri   r   r#   r   rQ   r   r$   r   r   r3   r3   r3   r4   r   *      r   c                   @  s   e Zd ZdZdddZdS )	#FreeModelBeforeValidatorWithoutInfoA `@model_validator` decorated function signature.
    This is used when `mode='before'` and the function does not have info argument.
    ri   r   r$   c                C  rj   rY   r3   )r1   ri   r3   r3   r4   rl   ?  r{   z,FreeModelBeforeValidatorWithoutInfo.__call__N)ri   r   r$   r   r   r3   r3   r3   r4   r   :  r   r   c                   @  s   e Zd ZdZd	ddZdS )
ModelBeforeValidatorWithoutInfor   r:   r   ri   r$   c                C  rj   rY   r3   rk   r3   r3   r4   rl   N  r   z(ModelBeforeValidatorWithoutInfo.__call__Nrn   r   r3   r3   r3   r4   r   I  r   r   c                   @  s   e Zd ZdZd
ddZd	S )FreeModelBeforeValidatorUA `@model_validator` decorated function signature. This is used when `mode='before'`.ri   r   rQ   rs   r$   c                C  rj   rY   r3   )r1   ri   rQ   r3   r3   r4   rl   \  r   z!FreeModelBeforeValidator.__call__N)ri   r   rQ   rs   r$   r   r   r3   r3   r3   r4   r   Y  r   r   c                   @  s   e Zd ZdZddd	Zd
S )ModelBeforeValidatorr   r:   r   ri   rQ   rs   r$   c                C  rj   rY   r3   rt   r3   r3   r4   rl   j  r   zModelBeforeValidator.__call__Nru   r   r3   r3   r3   r4   r   g  r   r   |Callable[[_AnyModelWrapValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rj   rY   r3   r)   r3   r3   r4   model_validator  r   r   Literal['before']rCallable[[_AnyModelBeforeValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rj   rY   r3   r   r3   r3   r4   r     r   }Callable[[_AnyModelAfterValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rj   rY   r3   r   r3   r3   r4   r     r   "Literal['wrap', 'before', 'after']c                   s   d fdd}|S )	a@  !!! abstract "Usage Documentation"
        [Model Validators](../concepts/validators.md#model-validators)

    Decorate model methods for validation purposes.

    Example usage:
    ```python
    from typing_extensions import Self

    from pydantic import BaseModel, ValidationError, model_validator

    class Square(BaseModel):
        width: float
        height: float

        @model_validator(mode='after')
        def verify_square(self) -> Self:
            if self.width != self.height:
                raise ValueError('width and height do not match')
            return self

    s = Square(width=1, height=1)
    print(repr(s))
    #> Square(width=1.0, height=1.0)

    try:
        Square(width=1, height=2)
    except ValidationError as e:
        print(e)
        '''
        1 validation error for Square
          Value error, width and height do not match [type=value_error, input_value={'width': 1, 'height': 2}, input_type=dict]
        '''
    ```

    For more in depth examples, see [Model Validators](../concepts/validators.md#model-validators).

    Args:
        mode: A required string literal that specifies the validation mode.
            It can be one of the following: 'wrap', 'before', or 'after'.

    Returns:
        A decorator that can be used to decorate a function to be used as a model validator.
    r   r   r$   r   c                   sN   t | }  dkrt| trtjtdt  ddd t j d}t 	| |S )Nr&   zUsing `@model_validator` with mode='after' on a classmethod is deprecated. Instead, use an instance method. See the documentation at https://docs.pydantic.dev/z,/concepts/validators/#model-after-validator.   )categorymessage
stacklevelr   )
r   r   r   rC   warningswarnr   r   ZModelValidatorDecoratorInfor   r   r   r3   r4   r     s   
	zmodel_validator.<locals>.decN)r   r   r$   r   r3   )r)   r   r3   r   r4   r     s   1AnyTypec                   @  s2   e Zd ZdZedddZedddZejZdS )
InstanceOfu  Generic type for annotating a type that is an instance of a given class.

        Example:
            ```python
            from pydantic import BaseModel, InstanceOf

            class Foo:
                ...

            class Bar(BaseModel):
                foo: InstanceOf[Foo]

            Bar(foo=Foo())
            try:
                Bar(foo=42)
            except ValidationError as e:
                print(e)
                """
                [
                │   {
                │   │   'type': 'is_instance_of',
                │   │   'loc': ('foo',),
                │   │   'msg': 'Input should be an instance of Foo',
                │   │   'input': 42,
                │   │   'ctx': {'class': 'Foo'},
                │   │   'url': 'https://errors.pydantic.dev/0.38.0/v/is_instance_of'
                │   }
                ]
                """
            ```
        itemr   r$   c                 C  s   t ||  f S rY   )r   r:   r   r3   r3   r4   __class_getitem__  s   zInstanceOf.__class_getitem__sourcer   r#   r   r%   c                 C  sh   ddl m} tt|p|}z||}W n |y!   | Y S w tjdd |d|d< tj||dS )Nr   rU   c                 S  rX   rY   r3   rZ   r3   r3   r4   r]   #  r^   z9InstanceOf.__get_pydantic_core_schema__.<locals>.<lambda>r_   r,   rW   )Zpython_schemaZjson_schema)ra   rV   r   Zis_instance_schemar   
get_originrc   Zjson_or_python_schema)r:   r   r#   rV   Zinstance_of_schemaoriginal_schemar3   r3   r4   r5     s   
z'InstanceOf.__get_pydantic_core_schema__N)r   r   r$   r   r   r   r#   r   r$   r%   )	r>   r?   r@   rA   rC   r   r5   object__hash__r3   r3   r3   r4   r     s     
r   c                   @  s.   e Zd ZdZdddZedddZejZdS )SkipValidationa  If this is applied as an annotation (e.g., via `x: Annotated[int, SkipValidation]`), validation will be
            skipped. You can also use `SkipValidation[int]` as a shorthand for `Annotated[int, SkipValidation]`.

        This can be useful if you want to use a type annotation for documentation/IDE/type-checking purposes,
        and know that it is safe to skip validation for one or more of the fields.

        Because this converts the validation schema to `any_schema`, subsequent annotation-applied transformations
        may not have the expected effects. Therefore, when used, this annotation should generally be the final
        annotation applied to a type.
        r   r   r$   c                 C  s   t |t f S rY   )r   r   r   r3   r3   r4   r   ;  s   z SkipValidation.__class_getitem__r   r#   r   r%   c                   sj   t   t dt || W d    n1 sw   Y  d fddgi}tj|tjdd  ddS )NignoreZ pydantic_js_annotation_functionsc                   s   | S rY   r3   )Z_cr\   r   r3   r4   r]   C  r^   z=SkipValidation.__get_pydantic_core_schema__.<locals>.<lambda>c                 S  rX   rY   r3   rZ   r3   r3   r4   r]   G  r^   r   )metadatarW   )r   catch_warningssimplefilterr   r   Z
any_schemarc   )r:   r   r#   r   r3   r   r4   r5   >  s   

z+SkipValidation.__get_pydantic_core_schema__N)r   r   r$   r   r   )	r>   r?   r@   rA   r   rC   r5   r   r   r3   r3   r3   r4   r   .  s    

r   
_FromTypeTc                   @  s$   e Zd ZdZddd	ZdddZdS )
ValidateAsa  A helper class to validate a custom type from a type that is natively supported by Pydantic.

    Args:
        from_type: The type natively supported by Pydantic to use to perform validation.
        instantiation_hook: A callable taking the validated type as an argument, and returning
            the populated custom type.

    Example:
        ```python {lint="skip"}
        from typing import Annotated

        from pydantic import BaseModel, TypeAdapter, ValidateAs

        class MyCls:
            def __init__(self, a: int) -> None:
                self.a = a

            def __repr__(self) -> str:
                return f"MyCls(a={self.a})"

        class Model(BaseModel):
            a: int


        ta = TypeAdapter(
            Annotated[MyCls, ValidateAs(Model, lambda v: MyCls(a=v.a))]
        )

        print(ta.validate_python({'a': 1}))
        #> MyCls(a=1)
        ```
    instantiation_hookCallable[[_FromTypeT], Any]	from_typetype[_FromTypeT]r$   Nonec                C  s   || _ || _d S rY   )r   r   )r1   r   r   r3   r3   r4   __init__t  s   
zValidateAs.__init__r   r   r#   r   r%   c                 C  s   || j }tj| j|dS )Nr+   )r   r   r0   r   )r1   r   r#   r,   r3   r3   r4   r5   x  s
   
z'ValidateAs.__get_pydantic_core_schema__N)r   r   r   r   r$   r   r   )r>   r?   r@   rA   r   r5   r3   r3   r3   r4   r   Q  s    
"r   r3   )r'   r   r   r   r)   r   r   r   rF   r   r$   r   )r'   r   r   r   r)   r   r   r   rF   r   r$   r   )
r'   r   r   r   r)   r   r   r   r$   r   )r'   r   r   r   r)   r   r   r   rF   r   r$   r   )r)   r   r$   r   )r)   r   r$   r   )r)   r   r$   r   )r)   r   r$   r   )YrA   
__future__r   Z_annotationsdataclassessysr   	functoolsr   typesr   typingr   r   r   r   r	   r
   r   r   r   Zpydantic_corer   r   Ztyping_extensionsr   r   	_internalr   r   r   Zannotated_handlersr   errorsr   versionr   r   r   version_infor   Zinspect_validatorr-   	dataclassZ
slots_truer   rE   rT   rd   rh   rr   rv   ry   r.   r/   Z_V2Validatorrf   rg   Z_V2WrapValidatorrC   staticmethodr|   rB   r}   r   r   r   r   r   ZValidatorFunctionWrapHandlerr   r   r   r   r   r   r   ZModelAfterValidatorWithoutInfoZValidationInfoZModelAfterValidatorZ_AnyModelWrapValidatorZ_AnyModelBeforeValidatorZ_AnyModelAfterValidatorr   r   r   r   r   r   r3   r3   r3   r4   <module>   s    ,
<BcJ
,


o

D<