o
    Si@                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ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dZdd	 Zed
fddZed
fddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zed
fdd Z d!d" Z!d#d$ Z"d%d& Z#d'd( Z$d)d* Z%dS ),    N)curryis_valid_argsis_partial_argsis_aritynum_required_argshas_varargshas_keywords)builtins)raisesTc                 C   sF   |  ds	d|  } |rd}nd}i }td|  d| t | |d S )N(z(%s)z1raise ValueError("function should not be called")zreturn Truezdef funcz:
    func)
startswithexecglobals)param_stringraise_if_calledbodyd r   Q/home/ubuntu/.local/lib/python3.10/site-packages/toolz/tests/test_inspect_args.py	make_func   s   
r   c                      s  t d tt fddsJ tt fddsJ t ddd   s%J tt fdds0J t ddd  d	s<J  d	d
sCJ  d	dsJJ  d	ddsRJ tt fdds]J t ddd  d	siJ  d	d
spJ  d	dswJ  d	ddsJ tt fddsJ d S )N c                      s     S Nr   r   fr   r   <lambda>   s    z test_make_func.<locals>.<lambda>c                          dS N   r   r   r   r   r   r          F)r   c                      r   r   r   r   r   r   r   r   !   r   zx, y=1r   x   r!   yc                          dddS Nr   r"      r   r   r   r   r   r   (       z(x, y=1)c                      r%   r&   r   r   r   r   r   r   /   r(   )r   r
   
ValueError	TypeErrorr   r   r   r   test_make_func   s$   
r+   Fc                    s  |   fdd} t d}| |sJ | |ddu sJ | |dddu s%J t d}| ||u s1J | |ds8J | |dds@J | |ddddu sKJ | |ddd	du sVJ | |dddu s`J | |ddd
du skJ t d}| |suJ | |ds|J | |ddsJ | |ddddu sJ | |ddd	du sJ | |dddu sJ | |ddd
du sJ t d}| |sJ | |dsJ | |ddsJ | |dddu sJ t d}| |sJ | |ddsJ | |ddd
sJ | |ddu sJ t d}| ||u sJ | |dsJ | |ddsJ | |ddsJ | |ddddu s)J | |ddd	du s5J t d}| ||u sBJ | |dsJJ | |ddsSJ | |dds\J | |ddddsgJ | |dddd	du stJ t d}| ||u sJ | |d|u sJ | |ddsJ | |ddd|u sJ | |ddddu sJ | |dddddu sJ | |dddddu sJ | ddu sJ d S )Nc                        | ||S r   r   r   argskwargsorig_check_validr   r   r   4   r(   ztest_is_valid.<locals>.<lambda>r   r   Fr    r!   r"   r$   r#   zx=1*args**kwargszx, *argszx, y=1, **kwargsr'   r!   r$   zza, b, c=3, d=4)c)eb)r   check_valid
incompleter   r   r0   r   test_is_valid2   sn   r>   c                    sr  |   fdd} t d}| ||u sJ | |dsJ | |dds#J | |ddds,J | |dddu s6J | |ddd	du sAJ t d
}| ||u sMJ | |dsTJ | |dds\J | |dddseJ | |ddddsoJ | |ddswJ | |ddd	du sJ t d}| |sJ | |ddu sJ | |ddsJ | |dd	du sJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |dddsJ | |dddsJ | |dddu sJ | |ddd	du sJ | |dddddu sJ t d}| ||u sJ | |ddd	|u sJ | |ddsJ | |ddds%J | |ddds/J | |dddds:J | |dddddu sGJ | |dddddu sTJ t d}| ||u saJ | |d|u skJ | |dddsuJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |dddd|u sJ | |dddddsJ | |ddddddddd
|u sJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |ddsJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |ddsJ d|_| |du s$J G d d! d!}| }| |d u s7J d S )"Nc                    r,   r   r   r-   r0   r   r   r   w   r(   z#test_is_valid_py3.<locals>.<lambda>z	x, *, y=1r   r    r"   r2   Fr6   zx, *args, y=1z*, y=1zx, *, yr#   )r$   r6   zx=1, *, y, z=3r'   r5   zw, x=2, *args, y, z=4z%a, b, c=3, d=4, *args, e=5, f=6, g, h   )g   )rA   h         	   za: int, b: floatr9   z(a: int, b: float) -> float"   c                   @       e Zd Zdd Zedd ZdS )z+test_is_valid_py3.<locals>.RaisesValueErrorc                 S      d S r   r   selfr   r   r   __call__      z4test_is_valid_py3.<locals>.RaisesValueError.__call__c                 S      t dNzTesting Python 3.4r)   rK   r   r   r   __signature__      z9test_is_valid_py3.<locals>.RaisesValueError.__signature__N__name__
__module____qualname__rM   propertyrR   r   r   r   r   RaisesValueError       rY   )r   rR   )r<   r=   r   rY   r   r0   r   test_is_valid_py3u   s   $r[   c                   C   s   t tdd ttdd d S NTr<   r=   )r>   r   r[   r   r   r   r   test_is_partial   s   r^   c                  C   sZ   ddd} t j| dd}t|dd t|dd t j| dd}t|dd t|dd d S )NTc                 S   s   z;t | |i | t | g|R  di | t | fi ||  t | g|R i |  t| tdd s9W d S |W S  tyE   Y dS  tyN   Y dS w )Nc                   S   rJ   r   r   r   r   r   r   r          z:test_is_valid_curry.<locals>.check_curry.<locals>.<lambda>TFr   )r   
isinstancetyper)   r*   )r   r.   r/   r=   r   r   r   check_curry   s   z(test_is_valid_curry.<locals>.check_curry)r=   r]   FT)	functoolspartialr>   r[   )rb   r<   r   r   r   test_is_valid_curry   s   
rf   c                  C   s   ddd} t | di sJ t | di sJ t | ddd isJ t | ddd idu s+J t| di s3J t| di s;J t| ddd isEJ t| ddd idu sQJ d S )Nc                 S   rJ   r   r   r   r   r   r   r      rN   ztest_func_keyword.<locals>.fr   r   r   F)r   r   r   r   r   r   test_func_keyword   s   
rh   c                  C   s   t ddu sJ t tsJ t tddu sJ t tddu s"J t tds*J t tddu s4J t tds<J t tddu sFJ t td	du sPJ td} d
| _t | du s_J G dd d}| } t | d u sqJ d S )Nr   Fr   zx, y, zr3   r4   zx, y, *args, **kwargsz	x, y, z=1zx, y, z=1, **kwargsrH   c                   @   rI   )z/test_has_unknown_args.<locals>.RaisesValueErrorc                 S   rJ   r   r   rK   r   r   r   rM     rN   z8test_has_unknown_args.<locals>.RaisesValueError.__call__c                 S   rO   rP   rQ   rK   r   r   r   rR     rS   z=test_has_unknown_args.<locals>.RaisesValueError.__signature__NrT   r   r   r   r   rY     rZ   rY   )r   mapr   rR   )r   rY   r   r   r   test_has_unknown_args   s   rj   c                   C   s   t dd dks
J t dd dksJ t dd dksJ t dd dks(J t dd d	ks2J t td	ks:J t td u sBJ d S )
Nc                   S   rJ   r   r   r   r   r   r   r     r_   z(test_num_required_args.<locals>.<lambda>r   c                 S   rJ   r   r   r    r   r   r   r     r_   r   c                 W   rJ   r   r   r!   r.   r   r   r   r     r_   c                 [   rJ   r   r   r!   r/   r   r   r   r     r_   c                 _   rJ   r   r   )r!   r$   r.   r/   r   r   r   r     r_   r"   )r   ri   dictr   r   r   r   test_num_required_args  s   rn   c                   C   s   t dd du s
J t dd du sJ t d	ddsJ t dd s%J t ts+J t ts1J t ts7J t ttjd dkksDJ t td u sLJ d S )
Nc                   S   rJ   r   r   r   r   r   r   r     r_   z#test_has_keywords.<locals>.<lambda>Fc                 S   rJ   r   r   r    r   r   r   r     r_   r   c                 S   rJ   r   r   r    r   r   r   r     r_   c                  [   rJ   r   r   r/   r   r   r   r     r_      )r   )r   intsortedmaxri   sysversion_info	bytearrayr   r   r   r   test_has_keywords  s   rw   c                   C   sX   t dd du s
J t dd sJ t dd du sJ t ts"J t td u s*J d S )Nc                   S   rJ   r   r   r   r   r   r   r   '  r_   z"test_has_varargs.<locals>.<lambda>Fc                  W   rJ   r   r   )r.   r   r   r   r   (  r_   c                  [   rJ   r   r   ro   r   r   r   r   )  r_   )r   ri   rs   r   r   r   r   test_has_varargs&  s
   rx   c                   C   s   t ddd s	J t ddd du sJ t ddd sJ t dd	d s&J t dd
d du s1J t ddd du s<J t dtsCJ t dtdu sLJ t dtd u sUJ d S )Nr   c                   S   rJ   r   r   r   r   r   r   r   /  r_   ztest_is_arity.<locals>.<lambda>r   c                   S   rJ   r   r   r   r   r   r   r   0  r_   Fc                 S   rJ   r   r   r    r   r   r   r   1  r_   r'   c                 S   rJ   r   r   r5   r   r   r   r   2  r_   c                 W   rJ   r   r   rk   r   r   r   r   3  r_   c                 [   rJ   r   r   rl   r   r   r   r   4  r_   r"   )r   allri   ranger   r   r   r   test_is_arity.  s   r{   c                    s  |   fdd} t td}| |sJ | |dsJ | |dds$J | |ddds-J | |dddddu s9J | |d	d
du sCJ | |dsKJ | |ddsTJ | |ddds^J | |dddddu skJ | |ddddu swJ | |dddsJ | |ddddu sJ | |ddddsJ | |dddsJ | |dddddsJ | |dddddu sJ t jtdddd}| |du sJ | |dddu sJ t td}| |sJ | |dsJ | |ddsJ | |dddsJ | |dddds
J | |dddddsJ | |dddddds%J | |dds/J | |ddddu s<J | |ddddsHJ d S )Nc                    r,   r   r   )_funcr.   r/   r0   r   r   r   <  r(   z1test_introspect_curry_valid_py3.<locals>.<lambda>	x, y, z=0r   r"   r'   rD   FT)invalid_keywordr    r2   r?   zx, y, *args, zr   )toolzr   r   r;   r   r0   r   test_introspect_curry_valid_py3:  sD   r   c                   C   s   t tdd d S r\   )r   r   r   r   r   r   !test_introspect_curry_partial_py3b     r   c                  C   sf  t td} t| dksJ td| sJ t| du sJ t| du s&J t td} t| dks5J td| du s>J td| du sGJ t| du sOJ t| sUJ t td} t| dksdJ td| du smJ td| du svJ td| du sJ td| du sJ t| du sJ t| sJ t td	} t| dksJ t| sJ t| sJ d S )
Nr   r   Fr!   r   r}   r"   r'   z*args, **kwargs)r   r   r   r   r   r   r   r   r   r   r   test_introspect_curry_py3f  s.   r   c               	      s  t tttttjtjtjtjg	} t	   fdd}|t d |t d |t d |t d  fdd}i }| D ]%}|j
}t| D ]\}}||||rZ||vrSg ||< || | qAq6|rg }t| D ]\}}	d	|d
t|	}
||
 qfd}t|d| d S )Nc                    s"   t | |r t| | d S d S r   )hasattraddgetattr)modattrdenylistr   r   add_denylist  s   
z5test_introspect_builtin_modules.<locals>.add_denylist
basestringNoneType__metaclass__sequenceiteratorc                    s   | dr| dsdS | ds|drdS z
t|tr!W dS W n	 ty+   Y nw zt|oF|jd uoF| |jv oFt|di duoF| vW S  tyQ   Y dS w )N___F__pyx_unpickle_	_cython__r   T)	r   endswith
issubclassBaseExceptionr*   callablerV   r   AttributeError)modnamenamer   r   r   r   
is_missing  s0   
z3test_introspect_builtin_modules.<locals>.is_missingz
{}:
    {}z
    z4Missing introspection for the following callables:

z

)r	   rd   	itertoolsoperatorr   	functoolz	itertoolz	dicttoolzrecipessetrU   varsitemsappendrr   formatjoinAssertionError)modsr   r   missingr   r   r   r   messagesnamesmsgmessager   r   r   test_introspect_builtin_modules  s8   




r   c                  C   s   G dd d} | dd }t |}|t jt dt jjt dt jjgdks*J t| du s2J td	d
d fftj| < t| dksGJ tj| = d S )Nc                   @   (   e Zd Zdd Zdd Zedd ZdS )z-test_inspect_signature_property.<locals>.AddXc                 S   
   || _ d S r   rg   rL   r   r   r   r   __init__     
z6test_inspect_signature_property.<locals>.AddX.__init__c                 _   s   || j |i | S r   rg   )rL   addxr.   r/   r   r   r   rM     s   z6test_inspect_signature_property.<locals>.AddX.__call__c                 S   sD   t | j}t|j }t jj}t d|}|g| }|j|dS )Nr   
parameters)	inspect	signaturer   listr   values	ParameterPOSITIONAL_OR_KEYWORDreplace)rL   sigparamskindnewparamr   r   r   rR     s   
z;test_inspect_signature_property.<locals>.AddX.__signature__N)rU   rV   rW   r   rM   rX   rR   r   r   r   r   AddX  
    r   c                 S      | S r   r   r    r   r   r   r     r_   z1test_inspect_signature_property.<locals>.<lambda>r   r!   r   Fr   c                 S   rJ   r   r   rg   r   r   r   r     r_   r   )	r   r   	Signaturer   r   r   _sigs
expand_sig
signatures)r   r   r   r   r   r   test_inspect_signature_property  s   
r   c                  C   s   G dd d} dd }| |}t |t |ksJ d}tjjdkr%d}tjjdkr3tjjd	kr3d}tjjd
krAtjjdkrAd}tjjd
krId}|r`t| d u sSJ t	ddd fftj
| < t| dkshJ d S )Nc                   @   r   )z.test_inspect_wrapped_property.<locals>.Wrappedc                 S   r   r   rg   r   r   r   r   r     r   z7test_inspect_wrapped_property.<locals>.Wrapped.__init__c                 _   s   | j |i |S r   rg   )rL   r.   r/   r   r   r   rM     r   z7test_inspect_wrapped_property.<locals>.Wrapped.__call__c                 S   s   | j S r   rg   rK   r   r   r   __wrapped__  s   z:test_inspect_wrapped_property.<locals>.Wrapped.__wrapped__N)rU   rV   rW   r   rM   rX   r   r   r   r   r   Wrapped  r   r   c                 S   r   r   r   r    r   r   r   r     r_   z/test_inspect_wrapped_property.<locals>.<lambda>Tr'   F   rB      r"   r   c                 S   rJ   r   r   rg   r   r   r   r     r_   r   )r   r   rt   ru   majorminormicror   r   r   r   )r   r   wrappedinspectbrokenr   r   r   test_inspect_wrapped_property  s"   r   rc   )&rd   r   r   r   rt   r   toolz.functoolzr   r   r   r   r   r   r   toolz._signaturesr	   _signaturesr   toolz.utilsr
   r   r+   r>   r[   r^   rf   rh   rj   rn   rw   rx   r{   r   r   r   r   r   r   r   r   r   r   <module>   s8    $
CV
(3!