
    ii                    >   d dl mZ d dlmZ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  ed          Z e
d          Z G d	 d
e          Z G d d          Z G d d          Z G d deeef                   Z G d d          Z G d d          ZdS )    )annotations)AnyCallableGeneric	TypedDictTypeVarcast)	ParamSpec)ParameterException)deprecation)is_safe_subclassTPc                      e Zd ZU dZded<   dS )WrappedCallablezVA ref storing a callable. This class is a utility meant to prevent binding of methods.r   valueN)__name__
__module____qualname____doc____annotations__     j/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/polyfactory/fields.pyr   r      s         ``OOOOOr   r   c                      e Zd ZdZdS )RequirezGA factory field that marks an attribute as a required build-time kwarg.Nr   r   r   r   r   r   r   r   r      s        QQQQr   r   c                      e Zd ZdZdS )Ignorez3A factory field that marks an attribute as ignored.Nr   r   r   r   r   r      s        ====r   r   c                  &    e Zd ZdZdZddZddZdS )Usez~Factory field used to wrap a callable.

    The callable will be invoked whenever building the given factory attribute.


    argsfnkwargsr$   Callable[P, T]r#   P.argsr%   P.kwargsreturnNonec                4    d|i| _         || _        || _        dS )zWrap a callable.

        :param fn: A callable to wrap.
        :param args: Any args to pass to the callable.
        :param kwargs: Any kwargs to pass to the callable.
        r   Nr$   r%   r#   selfr$   r#   r%   s       r   __init__zUse.__init__'   !     %,R=			r   r   c                X    t          d | j        d         | j        i | j                  S )zNInvoke the callable.

        :returns: The output of the callable.


        r   r   )r	   r$   r#   r%   )r.   s    r   to_valuezUse.to_value2   s/     C))49DDDEEEr   N)r$   r&   r#   r'   r%   r(   r)   r*   )r)   r   r   r   r   r   	__slots__r/   r2   r   r   r   r!   r!      sS          )I	 	 	 	F F F F F Fr   r!   c                  &    e Zd ZdZdZdd
ZddZdS )PostGeneratedz\Factory field that allows generating values after other fields are generated by the factory.r"   r$   r   r#   r   r%   r)   r*   c                4    d|i| _         || _        || _        dS )zDesignate field as post-generated.

        :param fn: A callable.
        :param args: Args for the callable.
        :param kwargs: Kwargs for the callable.
        r   Nr,   r-   s       r   r/   zPostGenerated.__init__A   r0   r   namestrvaluesdict[str, Any]c                F     | j         d         ||g| j        R i | j        S )zInvoke the post-generation callback passing to it the build results.

        :param name: Field name.
        :param values: Generated values.

        :returns: An arbitrary value.
        r   )r$   r#   r%   )r.   r8   r:   s      r   r2   zPostGenerated.to_valueL   s1      twwfHtyHHHDKHHHr   N)r$   r   r#   r   r%   r   r)   r*   )r8   r9   r:   r;   r)   r   r3   r   r   r   r6   r6   <   sM        ff(I	 	 	 	I I I I I Ir   r6   c                  X    e Zd ZdZdZ ej        dd          ddd            ZddZdS )Fixturez8Factory field to create a pytest fixture from a factory.)r%   refsizez2.20.0zUse factory directly)versionalternativeNfixturer   r@   
int | Noner%   r   r)   r*   c                4    d|i| _         || _        || _        dS )zCreate a fixture from a factory.

        :param fixture: A factory that was registered as a fixture.
        :param size: Optional batch size.
        :param kwargs: Any build kwargs.
        r   N)r?   r@   r%   )r.   rC   r@   r%   s       r   r/   zFixture.__init__\   s"     &-g$6	r   c                    ddl m} | j        d         }t          ||          sd}t	          |          | j         |j        | j        fi | j        S  |j        di | j        S )z|Call the factory's build or batch method.

        :raises: ParameterException

        :returns: The build result.
        r   )BaseFactoryr   zDfixture has not been registered using the register_factory decoratorNr   )	polyfactory.factories.baserG   r?   r   r   r@   batchr%   build)r.   rG   factorymsgs       r   r2   zFixture.to_valueh   s     	;:::::(7#55 	*XC$S)))9  7=::dk:::w}++t{+++r   )N)rC   r   r@   rD   r%   r   r)   r*   )r)   r   )	r   r   r   r   r4   r   
deprecatedr/   r2   r   r   r   r>   r>   W   sk        BB)I[H:PQQQ	 	 	 	 RQ	, , , , , ,r   r>   N)
__future__r   typingr   r   r   r   r   r	   typing_extensionsr
   polyfactory.exceptionsr   polyfactory.utilsr   polyfactory.utils.predicatesr   r   r   r   r   r   r!   r6   r>   r   r   r   <module>rT      s   " " " " " " C C C C C C C C C C C C C C C C ' ' ' ' ' ' 5 5 5 5 5 5 ) ) ) ) ) ) 9 9 9 9 9 9GCLLIcNN    i   R R R R R R R R> > > > > > > >F F F F F'!Q$- F F F>I I I I I I I I6!, !, !, !, !, !, !, !, !, !,r   