Ë
    /æjH5  ã                  ó  — U 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	 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 ddl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!m"Z" d
dlm#Z# ddl$m%Z%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l0m1Z1 ddl2m3Z3 ddl4m5Z5 erddl6m7Z8 d
dl9m:Z:  G d„ de8e«      Z;	 d&	 	 	 	 	 	 	 d'd„Z<ddddœ	 	 	 	 	 	 	 	 	 	 	 d(d „Z=d)d!„Z>d*d"„Z?e@eAej„                  e   f   ZCd#eDd$<   ed+d%„«       ZEy),z0Private logic for creating pydantic dataclasses.é    )ÚannotationsN)Ú	Generator)Úcontextmanager)Úpartial)ÚTYPE_CHECKINGÚAnyÚClassVarÚProtocolÚ	TypeAliasÚcast)Ú
ArgsKwargsÚSchemaSerializerÚSchemaValidatorÚcore_schema)ÚTypeIsé   )ÚPydanticUndefinedAnnotation)Ú	FieldInfo)ÚPluggableSchemaValidatorÚcreate_schema_validator)ÚPydanticDeprecatedSince20é   )Ú_configÚ_decorators)Úcollect_dataclass_fields)ÚGenerateSchemaÚInvalidSchemaError)Úget_standard_typevars_map)Úset_dataclass_mocks)Ú
NsResolver)Úgenerate_pydantic_signature)ÚLazyClassAttribute)ÚDataclassInstance)Ú
ConfigDictc                  ój   — 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<   edd„«       Z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__z4ClassVar[SchemaValidator | PluggableSchemaValidator]Ú__pydantic_validator__c                 ó   — y ©N© ©Úclss    úb/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/pydantic/_internal/_dataclasses.pyÚ__pydantic_fields_complete__z.PydanticDataclass.__pydantic_fields_complete__=   s   € Ø7:ó    N)ÚreturnÚbool)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__Úclassmethodr4   r0   r5   r3   r&   r&   (   sA   … ñ
	ð 2Ó1Ø-Ó-Ø"BÓBØ!EÓEØ;Ó;Ø!;Ó;Ø TÓTà	Ú:ó 
Ù:r5   r&   c                óF   — t        | «      }t        | |||¬«      }|| _        y)zÚCollect and set `cls.__pydantic_fields__`.

    Args:
        cls: The class.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
    )Úns_resolverÚtypevars_mapÚconfig_wrapperN)r   r   r+   )r2   rA   r?   r@   Úfieldss        r3   Úset_dataclass_fieldsrC   A   s,   € ô -¨SÓ1€LÜ%Ø˜°<ÐP^ô€Fð %€CÕr5   TF)Úraise_errorsr?   Ú_force_buildc               óÂ  — | j                   }dd„}| j                  › d�|_        || _         |j                  | _        t	        | ||¬«       |s|j
                  rt        | «       yt        | d«      rt        j                  dt        «       t        | «      }t        |||¬«      }t        dt        t        || j                   |j"                  |j$                  d	¬
«      «      | _        	 |j)                  | «      }	|j/                  | j0                  ¬«      }	 |j3                  |	«      }	t7        d| «      } |	| _        t;        |	| | j<                  | j                  d||j>                  «      | _         tC        |	|«      | _"        d	| _#        y	# t*        $ r5}
|r‚ t        | |
j,                  �d|
j,                  › d�nd«       Y d}
~
yd}
~
ww xY w# t4        $ r t        | «       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`.
        ns_resolver: The namespace resolver instance to use when collecting dataclass fields
            and during schema building.
        _force_build: Whether to force building the dataclass, no matter if
            [`defer_build`][pydantic.config.ConfigDict.defer_build] is set.

    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.
    c                óZ   — d}| }|j                   j                  t        ||«      |¬«       y )NT)Úself_instance)r-   Úvalidate_pythonr   )Ú__dataclass_self__ÚargsÚkwargsÚ__tracebackhide__Úss        r3   Ú__init__z$complete_dataclass.<locals>.__init__v   s.   € Ø ÐØˆØ	× Ñ ×0Ñ0´¸DÀ&Ó1IÐYZÐ0Õ[r5   z	.__init__)rA   r?   FÚ__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be called)r?   r@   Ú__signature__T)ÚinitrB   Úvalidate_by_aliasÚextraÚis_dataclassNú`)Útitleztype[PydanticDataclass]Ú	dataclass)rJ   r&   rK   r   rL   r   r6   ÚNone)$rO   r:   Úconfig_dictr'   rC   Údefer_buildr   ÚhasattrÚwarningsÚwarnr   r   r   r"   r   r!   r+   rS   rT   rQ   Úgenerate_schemar   ÚnameÚcore_configr8   Úclean_schemar   r   r)   r   r9   Úplugin_settingsr-   r   r,   r(   )r2   rA   rD   r?   rE   Úoriginal_initrO   r@   Ú
gen_schemaÚschemaÚera   s               r3   Úcomplete_dataclassrh   U   sØ  € ð: —L‘L€Mó\ð
  #×/Ñ/Ð0°	Ð:€HÔà€C„LØ,×8Ñ8€CÔä˜¨^ÈÕUá˜N×6Ò6Ü˜CÔ ØäˆsÐ.Ô/Ü�‰ØdÜ%ô	
ô
 -¨SÓ1€LÜØØØ!ô€Jô +ØÜÜ'ð Ø×*Ñ*Ø,×>Ñ>Ø ×&Ñ&Øô		
ó€CÔðØ×+Ñ+¨CÓ0ˆð !×,Ñ,°3·<±<Ð,Ó@€KðØ×(Ñ(¨Ó0ˆô Ð(¨#Ó
.€Cà#)€CÔ Ü!8Ø��S—^‘^ S×%5Ñ%5°{ÀKÐQ_×QoÑQoó"€CÔô #3°6¸;Ó"G€CÔØ $€CÔØøô1 'ò ÙØÜ˜C°!·&±&Ð2D 1 Q§V¡V H¨A¡È$ÔOÜûð	ûô ò Ü˜CÔ Ùðús*   Ã'F ÄG Æ	GÆ+F?Æ?GÇGÇGc               ó<   — d| j                   v xr t        | d«       S )af  Returns `True` if the class is a stdlib dataclass and *not* a Pydantic dataclass.

    Unlike the stdlib `dataclasses.is_dataclass()` function, this does *not* include subclasses
    of a dataclass that are themselves not dataclasses.

    Args:
        cls: The class.

    Returns:
        `True` if the class is a stdlib dataclass, `False` otherwise.
    Ú__dataclass_fields__r-   )Ú__dict__r\   r1   s    r3   Úis_stdlib_dataclassrl   Á   s#   € ð " S§\¡\Ð1Ò`¼'À#ÐG_Ó:`Ð6`Ð`r5   c                ó&  — d| i}t         j                  dk\  r| j                  �| j                  |d<   | j                  �| j                  |d<   | j                  dur| j                  |d<   | j
                  du rd|d<   t        j                  d	i |¤ŽS )
NÚdefault)é   é   ÚdocÚkw_onlyTÚreprFrR   r0   )ÚsysÚversion_infoÚdescriptionrr   rs   rR   ÚdataclassesÚfield)Úpydantic_fieldÚ
field_argss     r3   Úas_dataclass_fieldr{   Ð   s£   € Ø"+¨^Ð!<€Jô ×Ñ˜7Ò" ~×'AÑ'AÐ'MØ*×6Ñ6ˆ
�5Ñð ×ÑÐ)Ø .× 6Ñ 6ˆ
�9Ñð ×Ñ $Ñ&Ø+×0Ñ0ˆ
�6Ñð ×Ñ˜eÑ#Ø"ˆ
�6Ñä×ÑÑ*˜zÑ*Ð*r5   r   ÚDcFieldsc           	   #  óÈ  K  — g }| j                   dd D �]k  }|j                  j                  di «      }|j                  «       D ��ci c]~  \  }}t	        |j
                  t        «      r_|j
                  j                  €F|j
                  j                  €0|j
                  j                  dus|j
                  j                  du r||“Œ€ }}}|sŒ¼|j                  ||f«       |j                  «       D ]Š  \  }}t        t        |j
                  «      }t        j                  |«      }|j                  �|j                  |_        |j                  dur|j                  |_	        |j                  du rd|_
        |||<   ŒŒ �Œn 	 d–— |D ]"  \  }	}
|
j                  «       D ]
  \  }}||	|<   Œ Œ$ yc c}}w # |D ]"  \  }	}
|
j                  «       D ]
  \  }}||	|<   Œ Œ$ w xY w­w)a°  Temporarily patch the stdlib dataclasses bases of `cls` if the Pydantic `Field()` function is used.

    When creating a Pydantic dataclass, it is possible to inherit from stdlib dataclasses, where
    the Pydantic `Field()` function is used. To create this Pydantic dataclass, we first apply
    the stdlib `@dataclass` decorator on it. During the construction of the stdlib dataclass,
    the `kw_only`, `repr` and `init` field arguments need to be understood by the stdlib *during* the
    dataclass construction. To do so, we temporarily patch the fields dictionary of the affected
    bases.

    For instance, with the following example:

    ```python {test="skip" lint="skip"}
    import dataclasses as stdlib_dc

    import pydantic
    import pydantic.dataclasses as pydantic_dc

    @stdlib_dc.dataclass
    class A:
        a: int = pydantic.Field(repr=False)

    # Notice that the `repr` attribute of the dataclass field is `True`:
    A.__dataclass_fields__['a']
    #> dataclass.Field(default=FieldInfo(repr=False), repr=True, ...)

    @pydantic_dc.dataclass
    class B(A):
        b: int = pydantic.Field(repr=False)
    ```

    When passing `B` to the stdlib `@dataclass` decorator, it will look for fields in the parent classes
    and reuse them directly. When this context manager is active, `A` will be temporarily patched to be
    equivalent to:

    ```python {test="skip" lint="skip"}
    @stdlib_dc.dataclass
    class A:
        a: int = stdlib_dc.field(default=Field(repr=False), repr=False)
    ```

    !!! note
        This is only applied to the bases of `cls`, and not `cls` itself. The reason is that the Pydantic
        dataclass decorator "owns" `cls` (in the previous example, `B`). As such, we instead modify the fields
        directly (in the previous example, we simply do `setattr(B, 'b', as_dataclass_field(pydantic_field))`).

    !!! note
        This approach is far from ideal, and can probably be the source of unwanted side effects/race conditions.
        The previous implemented approach was mutating the `__annotations__` dict of `cls`, which is no longer a
        safe operation in Python 3.14+, and resulted in unexpected behavior with field ordering anyway.
    r   Nrj   TF)Ú__mro__rk   ÚgetÚitemsÚ
isinstancern   r   rv   rr   rs   rR   Úappendr   Úcopy)r2   Úoriginal_fields_listÚbaseÚ	dc_fieldsÚ
field_namerx   Ú&dc_fields_with_pydantic_field_defaultsrn   Únew_dc_fieldrB   Úoriginal_fieldsÚoriginal_fields               r3   Úpatch_base_fieldsrŒ   ê   sð  è ø€ ðn =?Ðà—‘˜A˜B�ó 5ˆØ7;·}±}×7HÑ7HÐI_ÐacÓ7dˆ	ð &/§_¡_Ó%6÷2
á!�
˜EÜ˜%Ÿ-™-¬Ô3ð —‘×)Ñ)Ð5Ø—=‘=×(Ñ(Ð4Ø—=‘=×%Ñ%¨TÑ1Ø—=‘=×%Ñ%¨Ñ.ð ˜Ñð2
Ð.ñ 2
ò 2Ø ×'Ñ'¨Ð4ZÐ([Ô\Ø%K×%QÑ%QÓ%Sò 5Ñ!�
˜EÜœy¨%¯-©-Ó8�ô  $Ÿy™y¨Ó/�ð —?‘?Ð.Ø+2¯?©?�LÔ(Ø—<‘< tÑ+Ø(/¯©�LÔ%Ø—<‘< 5Ñ(Ø(-�LÔ%Ø(4�	˜*Ò%ò5ð!5ð>4Ûà';ò 	4Ñ#ˆF�OØ.=×.CÑ.CÓ.Eò 4Ñ*�
˜NØ%3��zÒ"ñ4ñ	4ùóA2
øð@ (<ò 	4Ñ#ˆF�OØ.=×.CÑ.CÓ.Eò 4Ñ*�
˜NØ%3��zÒ"ñ4ñ	4üs2   ‚AG"ÁBF0Ã
G"ÃB3G"ÆF6 Æ.G"Æ6)GÇG"r/   )r2   ztype[StandardDataclass]rA   ú_config.ConfigWrapperr?   úNsResolver | Noner6   rY   )r2   ú	type[Any]rA   r�   rD   r7   r?   rŽ   rE   r7   r6   r7   )r2   r�   r6   zTypeIs[type[StandardDataclass]])ry   r   r6   zdataclasses.Field[Any])r2   r�   r6   zGenerator[None])Fr;   Ú
__future__r   Ú_annotationsrƒ   rw   rt   r]   Úcollections.abcr   Ú
contextlibr   Ú	functoolsr   Útypingr   r   r	   r
   r   r   Úpydantic_corer   r   r   r   Útyping_extensionsr   Úerrorsr   rB   r   Úplugin._schema_validatorr   r   r   Ú r   r   Ú_fieldsr   Ú_generate_schemar   r   Ú	_genericsr   Ú_mock_val_serr   Ú_namespace_utilsr    Ú
_signaturer!   Ú_utilsr"   Ú	_typeshedr#   ÚStandardDataclassÚconfigr$   r&   rC   rh   rl   r{   ÚdictÚstrÚFieldr|   r<   rŒ   r0   r5   r3   ú<module>r¨      s1  ðÚ 6å 2ã Û Û 
Û Ý %Ý %Ý ß J× J÷ó õ %å 0Ý ß XÝ 0ß "Ý -ß @Ý 0Ý .Ý (Ý 3Ý &áÝ@å#ô;Ð-¨xô ;ð8 &*ð%Ø	 ð%à)ð%ð #ð%ð 
ó	%ð0 Ø%)ØñiØ	ðià)ðið ð	ið
 #ðið ðið 
óióXaó+ð. ˜3 × 1Ñ 1°#Ñ 6Ð6Ñ7€ˆ)Ó 7ð ò\4ó ñ\4r5   