
    o if3                       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;	 d7d8d$Z<d%dd&d'd9d,Z=d:d.Z>d;d2Z?e@eAejB        e         f         ZCd3eDd4<   ed<d6            ZEdS )=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                  r    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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__returnboolc                    d S N clss    V/var/www/findabus/venv/lib/python3.11/site-packages/pydantic/_internal/_dataclasses.py__pydantic_fields_complete__z.PydanticDataclass.__pydantic_fields_complete__=   s    7:s    N)r.   r/   )__name__
__module____qualname____doc____annotations__classmethodr6   r2   r7   r5   r&   r&   (   s         
	 
	 	2111----BBBBEEEE;;;;;;;;TTTT	::: 
:::r7   r&   r4   type[StandardDataclass]config_wrapper_config.ConfigWrapperns_resolverNsResolver | Noner.   Nonec                X    t          |           }t          | |||          }|| _        dS )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.
    )rA   typevars_mapr?   N)r   r   r+   )r4   r?   rA   rE   fieldss        r5   set_dataclass_fieldsrG   A   s?     -S11L%<P^  F %Cr7   TF)raise_errorsrA   _force_build	type[Any]rH   r/   rI   c                  | 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          d|           } |	| _        t;          |	| | j        | j        d||j                  | _         tC          |	|          | _"        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   kwargsr.   rC   c                b    d}| }|j                             t          ||          |           d S )NT)self_instance)r-   validate_pythonr   )rL   rM   rN   __tracebackhide__ss        r5   __init__z$complete_dataclass.<locals>.__init__v   s:     	 00D&1I1IYZ0[[[[[r7   z	.__init__)r?   rA   F__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be called)rA   rE   __signature__T)initrF   validate_by_nameextrais_dataclass`N)titleztype[PydanticDataclass]	dataclass)rL   r&   rM   r   rN   r   r.   rC   )$rT   r:   config_dictr'   rG   defer_buildr   hasattrwarningswarnr   r   r   r"   r   r!   r+   rX   rY   rV   generate_schemar   namecore_configr8   clean_schemar   r   r)   r   r9   plugin_settingsr-   r   r,   r(   )r4   r?   rH   rA   rI   original_initrT   rE   
gen_schemaschemaere   s               r5   complete_dataclassrl   U   sX   : LM\ \ \ \
  #/:::HCL,8C^UUUU N6 C   us.// 
d%	
 	
 	

 -S11L!  J +' *+< &		
 		
 		
 C++C00&    	CQV///uuuuu	 !,,3<,@@K((00   C   uu (#
.
.C#)C !8S^S%5{KQ_Qo" "C #36;"G"GC $C4s*   "C8 8
D)D$$D)E E;:E;TypeIs[type[StandardDataclass]]c               6    d| j         v o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`   r3   s    r5   is_stdlib_dataclassrq      s$     "S\1`'#G_:`:`6``r7   pydantic_fieldr   dataclasses.Field[Any]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rv   
   Tkw_onlyreprr2   )sysversion_infodescriptionr{   r|   dataclassesfield)rr   
field_argss     r5   as_dataclass_fieldr      s    "+^!<J 7""~'A'M*6
5 7""~'=" $
9 $&&+0
6**z***r7   r   DcFieldsGenerator[None]c              #    K   g }| j         dd         D ]}|j                            di           }d |                                D             }|r|                    ||f           |                                D ]k\  }}t          t          |j                  }t          j        |          }t          j
        dk    r|j        rd|_        |j        dur|j        |_        |||<   l	 dV  |D ]$\  }	}
|
                                D ]
\  }}||	|<   %dS # |D ]$\  }	}
|
                                D ]
\  }}||	|<   %w xY 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   Nro   c                    i | ]H\  }}t          |j        t                    r)|j        j        |j        j        s|j        j        duE||IS )NT)
isinstanceru   r   r   r{   r|   ).0
field_namer   s      r5   
<dictcomp>z%patch_base_fields.<locals>.<dictcomp>   si     2
 2
 2
!
E%-332

 *6%-:O6SXS`SemqSqSq	  TrSqSqr7   ry   T)__mro__rp   getitemsappendr   r   ru   copyr}   r~   r{   r|   )r4   original_fields_listbase	dc_fields&dc_fields_with_pydantic_field_defaultsr   r   ru   new_dc_fieldrF   original_fieldsoriginal_fields               r5   patch_base_fieldsr      s     n =?ABB 5 57;}7H7HI_ac7d7d	2
 2
%.__%6%62
 2
 2
. 2 	5 ''4Z([\\\%K%Q%Q%S%S 5 5!
Ey%-88  $y// #w..7?.+/L(<t++(/L%(4	*%%4'; 	4 	4#FO.=.C.C.E.E 4 4*
N%3z""4	4 	4'; 	4 	4#FO.=.C.C.E.E 4 4*
N%3z""4	4s   *D )E r1   )r4   r>   r?   r@   rA   rB   r.   rC   )r4   rJ   r?   r@   rH   r/   rA   rB   rI   r/   r.   r/   )r4   rJ   r.   rm   )rr   r   r.   rs   )r4   rJ   r.   r   )Fr;   
__future__r   _annotationsr   r   r}   ra   collections.abcr   
contextlibr   	functoolsr   typingr   r   r	   r
   r   pydantic_corer   r   r   r   typing_extensionsr   r   errorsr   rF   r   plugin._schema_validatorr   r   r    r   r   _fieldsr   _generate_schemar   r   	_genericsr   _mock_val_serr   _namespace_utilsr    
_signaturer!   _utilsr"   	_typeshedr#   StandardDataclassconfigr$   r&   rG   rl   rq   r   dictstrFieldr   r<   r   r2   r7   r5   <module>r      s   6 6 6 2 2 2 2 2 2      



  % % % % % % % % % % % %       ? ? ? ? ? ? ? ? ? ? ? ? ? ?            0 / / / / / / / 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 & & & & & & ;@@@@@@######; ; ; ; ;-x ; ; ;8 &*% % % % %0 %)i i i i i iXa a a a+ + + +$ 3 1# 667 7 7 7 7 U4 U4 U4 U4 U4 U4r7   