
    dhf3                       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 ddlmZmZmZmZ dd	l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%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cast)
ArgsKwargsSchemaSerializerSchemaValidatorcore_schema)	TypeAlias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    R/var/www/zara/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)zCollect 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1L%<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*        $ r'}
|r t        | d|
j,                   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&1IYZ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_nameextrais_dataclass`N)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   : LLM\
  #//0	:HCL,88C^UN66C s./d%	

 -S1L!J +' **+<< &&		
C++C0 !,,3<<,@K((0 (#
.C#)C !8S^^S%5%5{KQ_QoQo"C #36;"GC $C1 ' C1QVVHA/	  C s*   'F F9 	F6F11F69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<   t         j                  dk\  r| j                  rd|d<   | j                  dur| j                  |d<   t        j                  di |S )	Ndefault)      docro   
   Tkw_onlyreprr0   )sysversion_infodescriptionrt   ru   dataclassesfield)pydantic_field
field_argss     r3   as_dataclass_fieldr}      s    "+^!<J 7"~'A'A'M*66
5 7"~'='= $
9 $&+00
6*z**r5   r   DcFieldsc           	   #    K   g }| j                   dd D ]G  }|j                  j                  di       }|j                         D ci c]f  \  }}t	        |j
                  t              rG|j
                  j                  .|j
                  j                  s|j
                  j                  dur||h }}}|s|j                  ||f       |j                         D ]~  \  }}t        t        |j
                        }t        j                  |      }t        j                  dk\  r|j                  rd|_        |j                  dur|j                  |_	        |||<    J 	 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` and `repr` 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   Trr   )__mro__rk   getitems
isinstancern   r   rx   rt   ru   appendr   copyrv   rw   )r2   original_fields_listbase	dc_fields
field_namerz   &dc_fields_with_pydantic_field_defaultsrn   new_dc_fieldrB   original_fieldsoriginal_fields               r3   patch_base_fieldsr      s    n =?AB 57;}}7H7HI_ac7d	 &/__%62
!
E%--3**6%--:O:OSXS`S`SeSemqSq	 2
. 2
 2 ''4Z([\%K%Q%Q%S 5!
Ey%--8  $yy/ ##w.7??+/L(<<t+(/L%(4	*%5504'; 	4#FO.=.C.C.E 4*
N%3z"4	432
2 (< 	4#FO.=.C.C.E 4*
N%3z"4	4s2   AF>A+F2F>8B'F> F $.F>)F;;F>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]])r{   r   r6   zdataclasses.Field[Any])r2   r   r6   zGenerator[None])Fr;   
__future__r   _annotationsr   ry   rv   r]   collections.abcr   
contextlibr   	functoolsr   typingr   r   r	   r
   r   pydantic_corer   r   r   r   typing_extensionsr   r   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   
  % %  ? ?  0 0  X 0 " - @ 0 . ( 3 &@#;-x ;8 &*%	 %)% #% 
	%0 %)i	i)i 	i
 #i i 
iXa+$ 3 1 1# 667) 7 U4 U4r5   