
    h-i)                       d Z ddlmZ ddlZddlZddlZddl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mZ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 d	dl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'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ejb                  r2d	dl2m3Z3  G d dejh                        Z5 G d de5ejh                        Z6neZ7d#d$dZ8dd	 	 	 	 	 	 	 	 	 d%dZ9d&d Z:	 	 	 	 	 	 	 	 d'd!Z;d(d"Z<y))z0Private logic for creating pydantic dataclasses.    )annotationsN)partialwraps)	Parameter	Signature)AnyCallableClassVar)
ArgsKwargsPydanticUndefinedSchemaSerializerSchemaValidatorcore_schema)	TypeGuard   )PydanticUndefinedAnnotation)	FieldInfo)create_schema_validator)PydanticDeprecatedSince20   )_config_decorators_typing_extra)ConfigWrapper)collect_dataclass_fields)GenerateSchemagenerate_pydantic_signature)get_standard_typevars_map)set_dataclass_mocks)CallbackGetCoreSchemaHandler)is_valid_identifier)
ConfigDictc                  4    e Zd ZU ded<   ded<   ded<   d	dZy)
StandardDataclasszClassVar[dict[str, Any]]__dataclass_fields__zClassVar[Any]__dataclass_params__zClassVar[Callable[..., None]]__post_init__c                     y N )selfargskwargss      ^D:\DhanshreeandTeamAI\Github\ai_code\venv\Lib\site-packages\pydantic/_internal/_dataclasses.py__init__zStandardDataclass.__init__*   s        N)r,   objectr-   r1   returnNone)__name__
__module____qualname____annotations__r/   r*   r0   r.   r$   r$   %   s    66++44	r0   r$   c                  X    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   y)PydanticDataclassai  A protocol containing attributes only available once a class has been decorated as a Pydantic dataclass.

        Attributes:
            __pydantic_config__: Pydantic-specific configuration settings for the dataclass.
            __pydantic_complete__: Whether dataclass building is completed, or if there are still undefined fields.
            __pydantic_core_schema__: The pydantic-core schema used to build the SchemaValidator and SchemaSerializer.
            __pydantic_decorators__: Metadata containing the decorators defined on the dataclass.
            __pydantic_fields__: Metadata about the fields defined on the dataclass.
            __pydantic_serializer__: The pydantic-core SchemaSerializer used to dump instances of the dataclass.
            __pydantic_validator__: The pydantic-core SchemaValidator used to validate instances of the dataclass.
        zClassVar[ConfigDict]__pydantic_config__zClassVar[bool]__pydantic_complete__z ClassVar[core_schema.CoreSchema]__pydantic_core_schema__z$ClassVar[_decorators.DecoratorInfos]__pydantic_decorators__zClassVar[dict[str, FieldInfo]]__pydantic_fields__zClassVar[SchemaSerializer]__pydantic_serializer__zClassVar[SchemaValidator]__pydantic_validator__N)r4   r5   r6   __doc__r7   r*   r0   r.   r9   r9   -   s3    
	 21--"BB!EE;;!;; 99r0   r9   c                D    t        |       }t        | ||      }|| _        y)zCollect and set `cls.__pydantic_fields__`.

    Args:
        cls: The class.
        types_namespace: The types namespace, defaults to `None`.
    )typevars_mapN)r   r   r>   )clstypes_namespacerC   fieldss       r.   set_dataclass_fieldsrG   H   s$     -S1L%c?VF$Cr0   T)raise_errorsc          	     d   t        | d      rt        j                  dt               |t	        j
                  |       }t        | |       t        |       }t        |||      }t        | | j                  |      }dd}| j                   d|_        || _        |j                  | _        || _        t!        | dd      }	 |r+ || t#        t%        |j&                  d      |d	
            }	n|j'                  | d      }	|j1                  |       }	 |j3                  |	      }	t7        j8                  d|       } |	| _        t=        |	| | j>                  | j                  d||j@                        x| _!        tE        |	|      | _#        |jH                  r5tK        | jL                        dfd       }|jO                  d|       | _&        y# t(        $ r2}
|r t+        | | j,                  d|
j.                   d       Y d}
~
yd}
~
ww xY w# |j4                  $ r t+        | | j,                  d       Y yw xY w)a  Finish building a pydantic dataclass.

    This logic is called on a class which has already been wrapped in `dataclasses.dataclass()`.

    This is somewhat analogous to `pydantic._internal._model_construction.complete_model_class`.

    Args:
        cls: The class.
        config_wrapper: The config wrapper instance.
        raise_errors: Whether to raise errors, defaults to `True`.
        types_namespace: The types namespace.

    Returns:
        `True` if building a pydantic dataclass is successfully completed, `False` otherwise.

    Raises:
        PydanticUndefinedAnnotation: If `raise_error` is `True` and there is an undefined annotations.
    __post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be calledNc                Z    d}| }|j                   j                  t        ||      |       y )NT)self_instance)r@   validate_pythonr   )__dataclass_self__r,   r-   __tracebackhide__ss        r.   r/   z$complete_dataclass.<locals>.__init__   s.     	  00D&1IYZ0[r0   z	.__init____get_pydantic_core_schema__F)from_dunder_get_core_schemaunpack)ref_mode`zall referenced typesztype[PydanticDataclass]	dataclassc                ,    j                  | ||       y r)   )validate_assignment)instance__field__value	validators      r.   validated_setattrz-complete_dataclass.<locals>.validated_setattr   s    ))(GWEr0   T)rN   r9   r,   r   r-   r   r2   r3   )rY   r   rZ   strr[   r^   r2   r3   )(hasattrwarningswarnDeprecationWarningr   get_cls_types_namespacerG   r   r   generate_dataclass_signaturer>   r6   r/   config_dictr:   __signature__getattrr    r   generate_schemar   r   r4   namecore_configclean_schemaCollectedInvalidtypingcastr<   r   r5   plugin_settingsr@   r   r?   rX   r   __setattr____get__)rD   config_wrapperrH   rE   rC   
gen_schemasigr/   get_core_schemaschemaerj   r]   r\   s                @r.   complete_dataclassrx   U   s7   2 s./dfx	
 '??Do.,S1LJ 'sC,C,C^
TC\
  #//0	:HCL,88CCc#A4HO$,J66TYZ%F  //QV/WF !,,S1K((0 ++/
5C $*C -DS^^S%5%5{KQ_QoQo. C #36;"GC))	s		F 
 	F ,33D#>C ' C166(!}=	 && C/EFs+   ?A G H 	H(G>>H&H/.H/c                   | j                   }t        |t              r| j                  }|dk(  rt        }| j
                  }|j                  }|j                  }|t        |t              rt        |      r|}nt        |t              rt        |      r|}|j                   }|t        u r=|j                  t        u rt        j                  j                  }nt        j                   }| j#                  |||      S | S )zCustom processing where the parameter default is of type FieldInfo

    Args:
        param (Parameter): The parameter

    Returns:
        Parameter: The custom processed parameter
    r   )
annotationri   default)r{   
isinstancer   rz   r   ri   aliasvalidation_aliasr^   r!   r   default_factoryinspectr   emptydataclasses_HAS_DEFAULT_FACTORYreplace)paramparam_defaultrz   ri   r}   r~   r{   s          r.   process_param_defaultsr      s     MMM-+%%
 J zz##(99#
5#(>CVW\C]D(#.3FGW3X#D  '''',,0AA!++11 &::}}
w}OOLr0   c                <    t        | j                  ||t              S )zGenerate signature for a pydantic dataclass.

    Args:
        cls: The dataclass.
        fields: The model fields.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass signature.
    )initrF   rr   post_process_parameter)r   r/   r   )rD   rF   rr   s      r.   rd   rd      s     '\\&`v r0   c           	         t        j                  |       xrG t        | d       xr8 t        | j                        j                  t        t        | di                   S )a>  Returns True if a class is a stdlib dataclass and *not* a pydantic dataclass.

    We check that
    - `_cls` is a dataclass
    - `_cls` does not inherit from a processed pydantic dataclass (and thus have a `__pydantic_validator__`)
    - `_cls` does not have any annotations that are not dataclass fields
    e.g.
    ```py
    import dataclasses

    import pydantic.dataclasses

    @dataclasses.dataclass
    class A:
        x: int

    @pydantic.dataclasses.dataclass
    class B(A):
        y: int
    ```
    In this case, when we first check `B`, we make an extra check and look at the annotations ('y'),
    which won't be a superset of all the dataclass fields (only the stdlib fields i.e. 'x')

    Args:
        cls: The class.

    Returns:
        `True` if the class is a stdlib dataclass, `False` otherwise.
    r@   r7   )r   is_dataclassr_   setr%   
issupersetrg   )_clss    r.   is_builtin_dataclassr      sZ    > 	  & 	a677	a))*55c'$HY[]:^6_`r0   r)   )rD   type[StandardDataclass]rE   dict[str, Any] | Noner2   r3   )
rD   	type[Any]rr   z_config.ConfigWrapperrH   boolrE   r   r2   r   )r   r   r2   r   )rD   r   rF   zdict[str, FieldInfo]rr   r   r2   r   )r   r   r2   z"TypeGuard[type[StandardDataclass]])=rA   
__future__r   _annotationsr   r   rm   r`   	functoolsr   r   r   r   r   r	   r
   pydantic_corer   r   r   r   r   typing_extensionsr   errorsr   rF   r   plugin._schema_validatorr   r    r   r   r   r   _fieldsr   _generate_schemar   r   	_genericsr   _mock_val_serr   _schema_generation_sharedr    _utilsr!   TYPE_CHECKINGconfigr"   Protocolr$   r9   rb   rG   rx   r   rd   r   r*   r0   r.   <module>r      s   6 2     $ ( * *  ( 0  > 0 1 1 " - I 0 . C '	#FOO :-v :0 3
%" 	f	f)f 	f
 +f 
fR$N	 *>P]$"r0   