o
    $6dV*                     @  s  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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m Z m!Z!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, ddl-m.Z. ddl/m0Z0 ej1rd	dl2m3Z3 G dd dej4Z5G dd de5ej4Z6neZ7d5d6d d!Z8d"d#d7d)d*Z9d8d,d-Z:d9d0d1Z;d:d3d4Z<dS );z0Private logic for creating pydantic dataclasses.    )annotationsN)partialwraps)	Parameter	Signature	signature)AnyCallableClassVar)
ArgsKwargsPydanticUndefinedSchemaSerializerSchemaValidatorcore_schema)	TypeGuard   )PydanticUndefinedAnnotation)	FieldInfo)PydanticDeprecatedSince20   )_config_decorators_discriminated_union_typing_extra)collect_invalid_schemasflatten_schema_defsinline_schema_defs)collect_dataclass_fields)GenerateSchema)get_standard_typevars_map)set_dataclass_mock_validator)CallbackGetCoreSchemaHandler)
ConfigDictc                   @  s0   e Zd ZU ded< ded< ded< dddZdS )StandardDataclasszClassVar[dict[str, Any]]__dataclass_fields__zClassVar[Any]__dataclass_params__zClassVar[Callable[..., None]]__post_init__argsobjectkwargsreturnNonec                 O  s   d S N )selfr'   r)   r-   r-   vC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/_internal/_dataclasses.py__init__"   s   zStandardDataclass.__init__N)r'   r(   r)   r(   r*   r+   )__name__
__module____qualname____annotations__r0   r-   r-   r-   r/   r#      s
   
 r#   c                   @  sJ   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]Z__pydantic_complete__z ClassVar[core_schema.CoreSchema]__pydantic_core_schema__z$ClassVar[_decorators.DecoratorInfos]Z__pydantic_decorators__zClassVar[dict[str, FieldInfo]]__pydantic_fields__zClassVar[SchemaSerializer]__pydantic_serializer__zClassVar[SchemaValidator]__pydantic_validator__N)r1   r2   r3   __doc__r4   r-   r-   r-   r/   r5   %   s   
 r5   clstype[StandardDataclass]types_namespacedict[str, Any] | Noner*   r+   c                 C  s    t | }t| ||d}|| _dS )zCollect and set `cls.__pydantic_fields__`.

    Args:
        cls: The class.
        types_namespace: The types namespace, defaults to `None`.
    )typevars_mapN)r   r   r8   )r<   r>   r@   fieldsr-   r-   r/   set_dataclass_fields@   s   
rB   T)raise_errors	type[Any]config_wrapper_config.ConfigWrapperrC   boolc             
     s  t | drtdt |du rt| }t| | t| }t|||}ddd}| j	 d|_	t
| }|| _|| _|j| _t| dd}z|rV|| tt|jdd|dd}	n|j| dd}	W n" ty }
 z|ri t| | jd|
j d W Y d}
~
dS d}
~
ww || }||	}	t|	}	t|	rt| | jd dS td| } tt|	 | _}	t |	}t!|| | _" t#||| _$|j%rt&| 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`.
        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.
    Z__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be calledN__dataclass_self__r5   r'   r   r)   r*   r+   c                 _  s"   d}| }|j jt|||d d S )NT)Zself_instance)r:   Zvalidate_pythonr   )rH   r'   r)   Z__tracebackhide__sr-   r-   r/   r0   y   s   z$complete_dataclass.<locals>.__init__z	.__init__Z__get_pydantic_core_schema__F)Zfrom_dunder_get_core_schemaunpack)Zref_mode`zall referenced typesztype[PydanticDataclass]instance__fieldstr__valuec                   s     | || d S r,   )validate_assignment)rL   rM   rO   	validatorr-   r/   validated_setattr   s   z-complete_dataclass.<locals>.validated_setattrT)rH   r5   r'   r   r)   r   r*   r+   )rL   r   rM   rN   rO   rN   r*   r+   ))hasattrwarningswarnDeprecationWarningr   Zget_cls_types_namespacerB   r   r   r3   generate_dataclass_signaturer0   __signature__Zconfig_dictr6   getattrr!   r   Zgenerate_schemar   r    r1   namecore_configZcollect_definitionsr   r   typingcastr   Zapply_discriminatorsr7   r   r   r:   r   r9   rP   r   __setattr____get__)r<   rE   rC   r>   r@   Z
gen_schemar0   sigZget_core_schemaZschemaer\   Zsimplified_core_schemarS   r-   rQ   r/   complete_dataclassM   sn   



	

rc   r   c                 C  s   t | }i }|j D ]O}|j}t|trU|j}|dkrt}|j}|j	du r0t|j
tr0|j
}n	t|j	tr9|j	}|j}|tu rM|jtu rJtjj}ntj}|j|||d}|||j< qtt| ddS )a  Generate signature for a pydantic dataclass.

    This implementation assumes we do not support custom `__init__`, which is currently true for pydantic dataclasses.
    If we change this eventually, we should make this function's logic more closely mirror that from
    `pydantic._internal._model_construction.generate_model_signature`.

    Args:
        cls: The dataclass.

    Returns:
        The signature.
    r   N)
annotationr[   default)
parametersreturn_annotation)r   rf   valuesre   
isinstancer   rd   r   r[   Zvalidation_aliasaliasrN   r   default_factoryinspectr   emptydataclasses_HAS_DEFAULT_FACTORYreplacelist)r<   ra   Zfinal_paramsparamZparam_defaultrd   r[   re   r-   r-   r/   rX      s*   


rX   _cls"TypeGuard[type[StandardDataclass]]c                 C  s2   t | ot| d ot| 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:   r4   )rn   is_dataclassrT   setr$   
issupersetrZ   rs   r-   r-   r/   is_builtin_dataclass   s
   

ry   "TypeGuard[type[PydanticDataclass]]c                 C  s   t | o	d| jv S )zWhether a class is a pydantic dataclass.

    Args:
        cls: The class.

    Returns:
        `True` if the class is a pydantic dataclass, `False` otherwise.
    r:   )rn   ru   __dict__rx   r-   r-   r/   is_pydantic_dataclass  s   	r|   r,   )r<   r=   r>   r?   r*   r+   )
r<   rD   rE   rF   rC   rG   r>   r?   r*   rG   )r<   r=   r*   r   )rs   rD   r*   rt   )rs   rD   r*   rz   )=r;   
__future__r   Z_annotationsrn   rl   r]   rU   	functoolsr   r   r   r   r   r   r	   r
   Zpydantic_corer   r   r   r   r   Ztyping_extensionsr   errorsr   rA   r   r    r   r   r   r   Z_core_utilsr   r   r   _fieldsr   Z_generate_schemar   Z	_genericsr   Z_mock_val_serr    Z_schema_generation_sharedr!   TYPE_CHECKINGconfigr"   Protocolr#   r5   rW   rB   rc   rX   ry   r|   r-   r-   r-   r/   <module>   s@    
f
0%