o
    i-                     @   s   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m	Z	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 G d	d
 d
eZG dd deZedkr\e  dS dS )    N)TestCasenjit)typeserrorscgutils	signature)models)overloadSentryLiteralArgsoverload_methodregister_model	intrinsic	literallyc                   @   s   e Z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
dd Zejdd Zej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%S )&TestLiteralDispatchc                 C   sR   t dd }|D ]
}| ||| qt||jD ]\}}| |d j| qd S )Nc                 S   s   t | S Nr   x r   p/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_literal_dispatch.pyfoo      z4TestLiteralDispatch.check_literal_basic.<locals>.foor   )r   assertEqualzip
signaturesliteral_value)selfZliteral_argsr   litsigr   r   r   check_literal_basic   s   
z'TestLiteralDispatch.check_literal_basicc                 C   s    |  ddg |  ddg d S )N{   A  abcZcb123)r!   r   r   r   r   test_literal_basic   s   z&TestLiteralDispatch.test_literal_basicc                    s   t dd  t  fdd}d\}}| ||||d |   j\}| |d t| |j\}| |d t| | |d tj d S )	Nc                 S   s   t | d S )N   r   r   r   r   r   r   "      z4TestLiteralDispatch.test_literal_nested.<locals>.fooc                    s    | | S r   r   )yr   r   r   r   bar&   r(   z4TestLiteralDispatch.test_literal_nested.<locals>.bar)      r'   r      )r   r   r   r   literalassertNotIsInstanceLiteral)r   r+   r)   r   foo_sigZbar_sigr   r*   r   test_literal_nested!   s   
z'TestLiteralDispatch.test_literal_nestedc                    sH   dd l  t fdd}| |dd | |jd d td d S )Nr   c                    s
     | S r   r   r   numbar   r   r   6      
z7TestLiteralDispatch.test_literally_freevar.<locals>.foor"   )r5   r   r   r   r   r/   r   r   r   r4   r   test_literally_freevar2   s
    z*TestLiteralDispatch.test_literally_freevarc                 C   s   dd }|dd \}}|t \}}| |dd|dd | |jd d jd | |jd d jd | |d	d
|d	d
 | |jd d jd
 | |jd d jd
 d S )Nc                    s(   |  fdd| fdd  fS )Nc                    s   | dk r|S |  | d | S Nr.   r   nvalue)	inner_facr   r   	outer_fac?   s   z[TestLiteralDispatch.test_mutual_recursion_literal.<locals>.get_functions.<locals>.outer_facc                    s"   | dk rt |S |  | d | S r9   r   r:   )r>   r   r   r=   E   s   z[TestLiteralDispatch.test_mutual_recursion_literal.<locals>.get_functions.<locals>.inner_facr   )Zdecorr   )r=   r>   r   get_functions>   s
   zHTestLiteralDispatch.test_mutual_recursion_literal.<locals>.get_functionsc                 S   s   | S r   r   r   r   r   r   <lambda>M   s    zCTestLiteralDispatch.test_mutual_recursion_literal.<locals>.<lambda>
      r   r.         )r   r   r   r   )r   r?   Zref_outer_facZref_inner_facr>   r=   r   r   r   test_mutual_recursion_literal=   s   z1TestLiteralDispatch.test_mutual_recursion_literalc                    sx   t  fdd}t dd  tdddd}|di |}d	d
 di |}| || |j\}| |d td d S )Nc                    
    | |S r   r   abcinnerr   r   r   Y   r6   z>TestLiteralDispatch.test_literal_nested_multi_arg.<locals>.fooc                 S      | t | S r   r   r   r)   r   r   r   rL   ]   r(   z@TestLiteralDispatch.test_literal_nested_multi_arg.<locals>.innerr.   r'   r,   rG   c                 S   s   | | S r   r   rG   r   r   r   r@   c       zCTestLiteralDispatch.test_literal_nested_multi_arg.<locals>.<lambda>r   )r   dictr   r   r   r/   )r   r   kwargsgotexpectr2   r   rK   r   test_literal_nested_multi_argX   s   
z1TestLiteralDispatch.test_literal_nested_multi_argc                    sv   t  fdd}t dd  td}| tj}|dd|d W d    n1 s+w   Y  | d	t|j d S )
Nc                    rF   r   r   rG   rK   r   r   r   i   r6   z>TestLiteralDispatch.test_unsupported_literal_type.<locals>.fooc                 S   rM   r   r   rN   r   r   r   rL   m   r(   z@TestLiteralDispatch.test_unsupported_literal_type.<locals>.innerrA   r.   r'   rG   znumpy.ndarray)	r   npZarangeassertRaisesr   LiteralTypingErrorassertInstr	exception)r   r   Zarrraisesr   rK   r   test_unsupported_literal_typeh   s   

z1TestLiteralDispatch.test_unsupported_literal_typec                       t  fdd}t dd  tdddd}|di |}d	d
 di |}| || |j\\}}}| |tj | |tj | |jd | |tj | |jd d S )Nc                    s    | | || S r   r   rG   rK   r   r   r   x   s   z/TestLiteralDispatch.test_biliteral.<locals>.fooc                 S   rM   r   r   rN   r   r   r   rL   |   r(   z1TestLiteralDispatch.test_biliteral.<locals>.innerr.   r'   r,   rG   c                 S   s   | | | | S r   r   rG   r   r   r   r@          z4TestLiteralDispatch.test_biliteral.<locals>.<lambda>r   	r   rP   r   r   r0   r   r1   assertIsInstancer   r   r   rQ   rR   rS   type_atype_bZtype_cr   rK   r   test_biliteralv   s   
z"TestLiteralDispatch.test_biliteralc                    s   t dd  | tj  ddd W d    n1 sw   Y  t  fdd}| tj}|dd W d    n1 s@w   Y  | dt|j d S )	Nc                 W      t |S r   r   )rH   argsr   r   r   r      r   z7TestLiteralDispatch.test_literally_varargs.<locals>.foor.   r'   r,   c                    s    | | d S r   r   rH   rI   r*   r   r   r+         z7TestLiteralDispatch.test_literally_varargs.<locals>.barzCannot request literal type)r   rV   r   rW   TypingErrorrX   rY   rZ   )r   r+   r[   r   r*   r   test_literally_varargs   s   
z*TestLiteralDispatch.test_literally_varargsc                 C   s   t ddd}|dd d S )Nr.   c                 S      | t |fS r   r   rg   r   r   r   r      r(   z8TestLiteralDispatch.test_literally_defaults.<locals>.foorH   r.   r   r7   r   r   r   test_literally_defaults   s   z+TestLiteralDispatch.test_literally_defaultsc                    s*   t ddd t  fdd}|d d S )Nr.   c                 S   rk   r   r   rg   r   r   r   r      r(   z>TestLiteralDispatch.test_literally_defaults_inner.<locals>.fooc                    s    | d S r9   r   rl   r*   r   r   r+      r(   z>TestLiteralDispatch.test_literally_defaults_inner.<locals>.barrm   r   )r   r+   r   r*   r   test_literally_defaults_inner   s
   z1TestLiteralDispatch.test_literally_defaults_innerc                 C   sB   t dd }|d}| ||d | |jd d tj d S )Nc                 S   s
   t | S r   )r5   r   r   r   r   r   r      r6   z;TestLiteralDispatch.test_literally_from_module.<locals>.foor"   r   )r   r   py_funcr`   r   r   r1   )r   r   rR   r   r   r   test_literally_from_module   s
   
z.TestLiteralDispatch.test_literally_from_modulec                 C   sX   t dd }| tj}|dd W d    n1 sw   Y  | dt|j d S )Nc                 S   s   t d|  S r9   r   rg   r   r   r   r      r(   z1TestLiteralDispatch.test_non_literal.<locals>.foor.   r'   zInvalid use of non-Literal type)r   rV   r   ri   rX   rY   rZ   )r   r   r[   r   r   r   test_non_literal   s   
z$TestLiteralDispatch.test_non_literalc                    sT   t dd   dd}| | dd t  fdd}| }| ||  d S )Nc                 S   s   d}| t | t | S )Ni  r   )rH   rI   vr   r   r   r      s   z5TestLiteralDispatch.test_inlined_literal.<locals>.foor.   r'   c                     s   d} d} || dS )Nd   	   rg   r   rg   r*   r   r   r+      s   z5TestLiteralDispatch.test_inlined_literal.<locals>.bar)r   r   rp   )r   rR   r+   r   r*   r   test_inlined_literal   s   

z(TestLiteralDispatch.test_inlined_literalc                    r]   )Nc                    s    fdd}||S )Nc                    s   t | d   S NrA   r   )d)rH   rI   rL   r   r   closure      zGTestLiteralDispatch.test_aliased_variable.<locals>.foo.<locals>.closurer   )rH   rI   rJ   ry   rK   rg   r   r      s   z6TestLiteralDispatch.test_aliased_variable.<locals>.fooc                 S   rM   r   r   rN   r   r   r   rL      r(   z8TestLiteralDispatch.test_aliased_variable.<locals>.innerr.   r'   r,   rG   c                 S   s   |d| |   S rw   r   rG   r   r   r   r@      r^   z;TestLiteralDispatch.test_aliased_variable.<locals>.<lambda>r   r_   ra   r   rK   r   test_aliased_variable   s   
z)TestLiteralDispatch.test_aliased_variablec                    s   dd  t  fddt fdd}d}d}|||}| |||  |jd	 \}}| |tj | |j| | |tj d S )
Nc                 S      | | S r   r   rN   r   r   r   do_this      z;TestLiteralDispatch.test_overload_explicit.<locals>.do_thisc                    s    t dg | | dd S )Nr   c                 S   r|   r   r   rN   r   r   r   r@      rO   zPTestLiteralDispatch.test_overload_explicit.<locals>.ov_do_this.<locals>.<lambda>)r   Zfor_functionbindrN   )
ov_do_thisr   r   r      s   z>TestLiteralDispatch.test_overload_explicit.<locals>.ov_do_thisc                    
    | |S r   r   rg   r}   r   r   r      r6   z7TestLiteralDispatch.test_overload_explicit.<locals>.foor"   r#   r   )	r   r   r   r   r`   r   r1   r   r0   )r   r   rH   rI   rrb   rc   r   )r}   r   r   test_overload_explicit   s   
z*TestLiteralDispatch.test_overload_explicitc                    s   dd  t dd t fdd}t  fdd}d	}d
}|||}| |||  |jd \}}| |tj | |j| | |tj d S )Nc                 S   r|   r   r   rN   r   r   r   r}     r~   z;TestLiteralDispatch.test_overload_implicit.<locals>.do_thisc                 S      t | | S r   r   rN   r   r   r   hidden  r(   z:TestLiteralDispatch.test_overload_implicit.<locals>.hiddenc                    s   t | tjr fddS d S )Nc                    r   r   r   rN   r   r   r   r@     s   
 zPTestLiteralDispatch.test_overload_implicit.<locals>.ov_do_this.<locals>.<lambda>)
isinstancer   IntegerrN   r   r   r   r     s   z>TestLiteralDispatch.test_overload_implicit.<locals>.ov_do_thisc                    r   r   r   rg   r   r   r   r     r6   z7TestLiteralDispatch.test_overload_implicit.<locals>.foor"   r#   r   )	r   r   r   r   r`   r   r1   r   r0   )r   r   r   rH   rI   r   rb   rc   r   r}   r   r   test_overload_implicit  s   

z*TestLiteralDispatch.test_overload_implicitc                    s   dd  t dd t fdd}t  fdd}| tj}|d	d
d W d    n1 s3w   Y  | dt|j d S )Nc                 S   r|   r   r   rN   r   r   r   r}   .  r~   z=TestLiteralDispatch.test_overload_error_loop.<locals>.do_thisc                 S   r   r   r   rN   r   r   r   r   1  r(   z<TestLiteralDispatch.test_overload_error_loop.<locals>.hiddenc                    s&   t |tjrtd fdd}|S )NZoopsc                    r   r   r   rN   r   r   r   impl<  s   
zNTestLiteralDispatch.test_overload_error_loop.<locals>.ov_do_this.<locals>.impl)r   r   ZIntegerLiteralr   ZNumbaValueError)r   r)   r   r   r   r   r   5  s   
z@TestLiteralDispatch.test_overload_error_loop.<locals>.ov_do_thisc                    s    | t |S r   r   rg   r   r   r   r   @  rh   z9TestLiteralDispatch.test_overload_error_loop.<locals>.foor"   r#   rg   zRepeated literal typing request)r   r   rV   r   ZCompilerErrorrX   rY   rZ   )r   r   r   r[   r   r   r   test_overload_error_loop)  s   

z,TestLiteralDispatch.test_overload_error_loopN)__name__
__module____qualname__r!   r&   r3   r8   rE   rT   r\   rd   rj   unittestZexpectedFailurern   ro   rq   rr   rv   r{   r   r   r   r   r   r   r   r      s*    


r   c                   @   s   e Zd Zdd Zdd ZdS )!TestLiteralDispatchWithCustomTypec                    sp   G dd dt }G  fdddtj t G fdddtjt fddt|fd	d
} |fS )Nc                   @   s   e Zd Zdd ZdS )z@TestLiteralDispatchWithCustomType.make_dummy_type.<locals>.Dummyc                 S   s   |S r   r   r   rH   r   r   r   r   O  s   zDTestLiteralDispatchWithCustomType.make_dummy_type.<locals>.Dummy.litN)r   r   r   r   r   r   r   r   DummyN  s    r   c                          e Zd Z fddZ  ZS )zDTestLiteralDispatchWithCustomType.make_dummy_type.<locals>.DummyTypec                    s   t  | jdd d S )Ndummy)namesuper__init__r%   )	DummyType	__class__r   r   r   S  rz   zMTestLiteralDispatchWithCustomType.make_dummy_type.<locals>.DummyType.__init__r   r   r   r   __classcell__r   r   r   r   r   R  s    r   c                       r   )zITestLiteralDispatchWithCustomType.make_dummy_type.<locals>.DummyTypeModelc                    s   g }t  | ||| d S r   r   )r   ZdmmZfe_typemembers)DummyTypeModelr   r   r   r   X  s   zRTestLiteralDispatchWithCustomType.make_dummy_type.<locals>.DummyTypeModel.__init__r   r   )r   r   r   r   V  s    r   c                    s   dd }t   }||fS )Nc                 S   s   t |j| |}| S r   )r   Zcreate_struct_proxyreturn_typeZ	_getvalue)contextZbuilderr	   rf   r   r   r   r   codegen^  s   zVTestLiteralDispatchWithCustomType.make_dummy_type.<locals>.init_dummy.<locals>.codegenr   )Z	typingctxr   r    r   r   r   
init_dummy\  s   
zETestLiteralDispatchWithCustomType.make_dummy_type.<locals>.init_dummyc                     s    fdd} | S )Nc                      s     S r   r   r   r   r   r   ctori  s   zWTestLiteralDispatchWithCustomType.make_dummy_type.<locals>.dummy_overload.<locals>.ctorr   )r   r   r   r   dummy_overloadg  s   zITestLiteralDispatchWithCustomType.make_dummy_type.<locals>.dummy_overload)objectr   Typer   r
   ZStructModelr   r   )r   r   r   r   )r   r   r   r   make_dummy_typeM  s   
z1TestLiteralDispatchWithCustomType.make_dummy_typec                    s   |   \} t|ddd }t fdd| dd tfdd}| tj}|d	 W d    n1 s<w   Y  | d
t|j	 d S )Nr   c                 S   s   dd }|S )Nc                 S   re   r   r   r   r   r   r   r   v  r~   zZTestLiteralDispatchWithCustomType.test_overload_method.<locals>.lit_overload.<locals>.implr   )r   rH   r   r   r   r   lit_overloadt  s   zLTestLiteralDispatchWithCustomType.test_overload_method.<locals>.lit_overloadc                    s     }| | S r   )r   )rH   rx   )r   r   r   	test_impl{  s   
zITestLiteralDispatchWithCustomType.test_overload_method.<locals>.test_impl   c                    s    | d S r9   r   rl   )r   r   r   inside  r(   zFTestLiteralDispatchWithCustomType.test_overload_method.<locals>.inside   zCannot request literal type.)
r   r   r   r   rV   r   ri   rX   rY   rZ   )r   r   r   r   r[   r   )r   r   r   test_overload_methodp  s   

z6TestLiteralDispatchWithCustomType.test_overload_methodN)r   r   r   r   r   r   r   r   r   r   L  s    #r   __main__)numpyrU   r5   r   Znumba.tests.supportr   r   Z
numba.corer   r   r   Znumba.core.typingr	   Znumba.core.datamodelr
   Znumba.core.extendingr   r   r   r   r   Znumba.misc.specialr   r   r   r   mainr   r   r   r   <module>   s"      >C