
    ~lDh"                       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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j+        r'ddl,m-Z. ddl/m0Z0 ddl1m2Z2  G d de.ej3                  Z4neZ5	 	 d/d0d"Z6d#dd$d%d1d+Z7d2d.Z8dS )3z0Private 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InvalidSchemaError)get_standard_typevars_map)set_dataclass_mocks)
NsResolver)generate_pydantic_signature)LazyClassAttribute)DataclassInstance)
ConfigDict)	FieldInfoc                  Z    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<   dS )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__     `/users/jtampere/www/backend/venv/lib/python3.11/site-packages/pydantic/_internal/_dataclasses.pyr!   r!   %   sr         
	 
	 	2111----BBBBEEEE;;;;;;;;TTTTTTr/   r!   clstype[StandardDataclass]ns_resolverNsResolver | Noneconfig_wrapper_config.ConfigWrapper | NonereturnNonec                X    t          |           }t          | |||          }|| _        dS )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`.
    )r3   typevars_mapr5   N)r   r   r&   )r1   r3   r5   r:   fieldss        r0   set_dataclass_fieldsr<   @   s?     -S11L%<P^  F %Cr/   TF)raise_errorsr3   _force_build	type[Any]_config.ConfigWrapperr=   boolr>   c               L   | j         }dd}| j         d	|_        || _         |j        | _        t	          | ||
           |s|j        rt          |            dS t          | d          rt          j	        dt                     t          |           }t          |||          }t          dt          t          || j        |j        |j        d                    | _        	 |                    |           }	n4# t*          $ r'}
|r t          | d|
j         d           Y d}
~
dS d}
~
ww xY w|                    | j                  }	 |                    |	          }	n # t4          $ r t          |            Y dS w xY wt7          j        d|           } |	| _        t=          |	| | j        | j        d||j                   x| _!        tE          |	|          | _#        |j$        r;tK          | j&                  dfd            }|'                    d|           | _&        d| _(        dS )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.
    __dataclass_self__r!   argsr   kwargsr7   r8   c                b    d}| }|j                             t          ||          |           d S )NT)self_instance)r(   validate_pythonr   )rC   rD   rE   __tracebackhide__ss        r0   __init__z$complete_dataclass.<locals>.__init__u   s:     	 00D&1I1IYZ0[[[[[r/   z	.__init__)r5   F__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be called)r3   r:   __signature__T)initr;   validate_by_nameextrais_dataclass`N)titleztype[PydanticDataclass]	dataclassinstancefieldstrvaluec               6                         | ||           d S )N)validate_assignment)rU   rV   rX   	validators      r0   validated_setattrz-complete_dataclass.<locals>.validated_setattr   s!    ))(E5AAAAAr/   )rC   r!   rD   r   rE   r   r7   r8   )rU   r   rV   rW   rX   rW   r7   r8   ))rK   r+   config_dictr"   r<   defer_buildr   hasattrwarningswarnDeprecationWarningr   r   r   r   r   r&   rO   rP   rM   generate_schemar   namecore_configr)   clean_schemar   typingcastr$   r   r*   plugin_settingsr(   r	   r'   rZ   r   __setattr____get__r#   )r1   r5   r=   r3   r>   original_initrK   r:   
gen_schemaschemaere   r\   r[   s                @r0   complete_dataclassrp   T   s   : LM\ \ \ \
  #/:::HCL,8Ck.IIII N6 C   us.// 
dfx	
 	
 	
 -S11L!  J +' *+< &		
 		
 		
 C++C00&    	CQV///uuuuu	 !,,3<,@@K((00   C   uu +/
5
5C $*C -DS^S%5{KQ_Qo. . C #36;"G"GC) ?	s			B 	B 	B 	B 	B 
 		B ,33D#>> $C4s*   #C9 9
D*D%%D*	E E<;E<_cls"TypeGuard[type[StandardDataclass]]c           	         t          j        |           oSt          | d           oBt          | 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-   )dataclassesrQ   r_   set__dataclass_fields__
issupersetgetattr)rq   s    r0   is_builtin_dataclassry      sf    > 	 && 	a6777	a)**55c'$HY[]:^:^6_6_``r/   )NN)r1   r2   r3   r4   r5   r6   r7   r8   )r1   r?   r5   r@   r=   rA   r3   r4   r>   rA   r7   rA   )rq   r?   r7   rr   )9r,   
__future__r   _annotationsrt   rg   r`   	functoolsr   r   r   r   pydantic_corer   r	   r
   r   typing_extensionsr   errorsr   plugin._schema_validatorr   r   r    r   r   _fieldsr   _generate_schemar   r   	_genericsr   _mock_val_serr   _namespace_utilsr   
_signaturer   _utilsr   TYPE_CHECKING	_typeshedr   StandardDataclassconfigr   r;   r   Protocolr!   rb   r<   rp   ry   r.   r/   r0   <module>r      s   6 6 2 2 2 2 2 2       $ $ $ $ $ $ $ $                            ( ' ' ' ' ' 0 0 0 0 0 0 X X X X X X X X 0 0 0 0 0 0 " " " " " " " " - - - - - - @ @ @ @ @ @ @ @ 0 0 0 0 0 0 . . . . . . ( ( ( ( ( ( 3 3 3 3 3 3 & & & & & &	 3@@@@@@######""""""U U U U U-v U U U U0 3
 &*37% % % % %0 %)r r r r r rj" " " " " "r/   