
    g%                       d Z ddlm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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 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+ ejX                  r)ddl-m.Z/ ddl0m1Z1 ddl2m3Z3  G d de/ejh                        Z5neZ6	 	 d!	 	 	 	 	 	 	 d"dZ7dddd	 	 	 	 	 	 	 	 	 	 	 d#dZ8d$d Z9y)%z0Private logic for creating pydantic dataclasses.    )annotationsN)partialwraps)AnyClassVar)
ArgsKwargsSchemaSerializerSchemaValidatorcore_schema)	TypeGuard   )PydanticUndefinedAnnotation)PluggableSchemaValidatorcreate_schema_validator)PydanticDeprecatedSince20   )_config_decorators)collect_dataclass_fields)GenerateSchema)get_standard_typevars_map)set_dataclass_mocks)
NsResolver)CallbackGetCoreSchemaHandler)generate_pydantic_signature)LazyClassAttribute)DataclassInstance)
ConfigDict)	FieldInfoc                  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__z4ClassVar[SchemaValidator | PluggableSchemaValidator]__pydantic_validator__N)__name__
__module____qualname____doc____annotations__     T/var/www/openai/venv/lib/python3.12/site-packages/pydantic/_internal/_dataclasses.pyr!   r!   &   s3    
	 21--"BB!EE;;!;; TTr/   r!   c                F    t        |       }t        | |||      }|| _        y)zCollect and set `cls.__pydantic_fields__`.

    Args:
        cls: The class.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
        config_wrapper: The config wrapper instance, defaults to `None`.
    )ns_resolvertypevars_mapconfig_wrapperN)r   r   r&   )clsr2   r4   r3   fieldss        r0   set_dataclass_fieldsr7   A   s,     -S1L%<P^F %Cr/   TF)raise_errorsr2   _force_buildc               
   | j                   }dd}| j                   d|_        || _         |j                  | _        t	        | ||       |s#|j
                  rt        | | j                         yt        | d      rt        j                  dt               t        |       }t        |||      }t        dt        t         || j"                  |j$                  |j&                  d	
            | _        t+        | dd      }		 |	r+ |	| t-        t        |j.                  d      |d            }
n|j/                  | d      }
|j5                  | j                        }	 |j7                  |
      }
t;        j<                  d|       } |
| _        tA        |
| | jB                  | j                  d||jD                        x| _#        tI        |
|      | _%        |jL                  r5tO        | jP                        dfd       }|jS                  d|       | _(        d	| _*        y	# t0        $ r2}|r t        | | j                  d|j2                   d       Y d}~yd}~ww xY w# |j8                  $ 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`.
        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        r0   __init__z$complete_dataclass.<locals>.__init__v   s.     	  00D&1IYZ0[r/   z	.__init__)r4   F__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be called)r2   r3   __signature__T)initr6   populate_by_nameextrais_dataclass__get_pydantic_core_schema__N)from_dunder_get_core_schemaunpack)ref_mode`)titlezall referenced typesztype[PydanticDataclass]	dataclassc               ,    j                  | ||       y )N)validate_assignment)instancefieldvalue	validators      r0   validated_setattrz-complete_dataclass.<locals>.validated_setattr   s    ))(E5Ar/   )r>   r!   r?   r   r@   r   returnNone)rS   r   rT   strrU   rZ   rX   rY   )+rC   r+   config_dictr"   r7   defer_buildr   r)   hasattrwarningswarnDeprecationWarningr   r   r   r   r   r&   rG   rH   rE   getattrr   generate_schemar   namecore_configclean_schemaCollectedInvalidtypingcastr$   r   r*   plugin_settingsr(   r	   r'   rR   r   __setattr____get__r#   )r5   r4   r8   r2   r9   original_initrC   r3   
gen_schemaget_core_schemaschemaerd   rW   rV   s                 @r0   complete_dataclassrq   U   s{   : LLM\
  #//0	:HCL,88Ck.IN66C.s./dfx	
 -S1L!J +' **+<< &&		
C c#A4HO$,J66TYZ%F  //QV/WF !,,3<<,@K((0 ++/
5C $*C -DS^^S%5%5{KQ_QoQo. C #36;"GC))	s		B 
 	B ,33D#> $CE ' C166(!}=	 && C/EFs+    A H I 	I$(II&JJc           	         t        j                  |       xrG t        | d       xr8 t        | j                        j                  t        t        | di                   S )aB  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.
    ```python
    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(   r-   )dataclassesrI   r]   set__dataclass_fields__
issupersetra   )_clss    r0   is_builtin_dataclassrx      sZ    > 	  & 	a677	a))*55c'$HY[]:^6_`r/   )NN)r5   ztype[StandardDataclass]r2   NsResolver | Noner4   z_config.ConfigWrapper | NonerX   rY   )r5   	type[Any]r4   z_config.ConfigWrapperr8   boolr2   ry   r9   r{   rX   r{   )rw   rz   rX   z"TypeGuard[type[StandardDataclass]]):r,   
__future__r   _annotationsrs   rg   r^   	functoolsr   r   r   r   pydantic_corer   r	   r
   r   typing_extensionsr   errorsr   plugin._schema_validatorr   r   r    r   r   _fieldsr   _generate_schemar   	_genericsr   _mock_val_serr   _namespace_utilsr   _schema_generation_sharedr   
_signaturer   _utilsr   TYPE_CHECKING	_typeshedr   StandardDataclassconfigr   r6   r   Protocolr!   r`   r7   rq   rx   r.   r/   r0   <module>r      s   6 2    $    ( 0 X 0 " - , 0 . ( C 3 &	@#"U-v U0 3
 &*37%	 %"% 1% 
	%0 %)|	|)| 	|
 #| | 
|~"r/   