
    shP+                     $   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	r	S SK
Jr  S SKJr  S SKJr  S SKJrJr   " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      rS rS rS rS r\S:X  a  \R:                  " 5         gg)    N)get_context)TypingError)TestCase)resolve_dispatcher_from_strdumpsloadsc                       \ rS rSrS r\R                  S 5       rS rS r	S r
S rS rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSrg)TestDispatcherPickling   c                 b    [        [        R                  S-   5       H  nU" U/UQ70 UD6  M     g )N   )rangepickleHIGHEST_PROTOCOL)selfmethargskwargsprotos        n/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/tests/test_serialize.pyrun_with_protocols)TestDispatcherPickling.run_with_protocols   s.    622Q67E((( 8    c              #      #    Sn[        U5      nUR                  n[        UR                  5      " U5      Ul         S v   X2l        g ! X2l        f = f7f)Ncpu)r   targetdescrtype)r   hwstrdispatcher_cls	old_descrs       r   simulate_fresh_target,TestDispatcherPickling.simulate_fresh_target   sM     4U;"..	%).*D*D%Ee%L"	3 *3&&s   :AA AAAc                    ^ ^^ UUU 4S jnU" U5        [         R                  " X!5      nT R                  5          [         R                  " U5      nU" U5        S S S 5        g ! , (       d  f       g = f)Nc                    > [        T[        5      (       a*  [        T[        5      (       a  TR                  " TU /TQ76   g TR                  U " T6 T5        g )N)
isinstancer   
issubclass	ExceptionassertRaisesassertPreciseEqual)funcr   expected_resultr   s    r   check_result7TestDispatcherPickling.check_call.<locals>.check_result&   sF    ?D11	::!!/4?$?''d_Er   )r   r   r"   r	   )r   r   r+   r,   r   r-   picklednew_funcs   `  ``   r   
check_call!TestDispatcherPickling.check_call%   sO    	F 	T,,t+'')||G,H" *))s   A""
A0c                     SSK Jn  U R                  U R                  USS5        U R                  U R                  USS5        g )Nr   )add_with_sig   r      )333333?g@)serialize_usecasesr4   r   r1   )r   r4   s     r   test_call_with_sig)TestDispatcherPickling.test_call_with_sig4   s5    4q&Iq*Mr   c                     SSK Jn  U R                  U R                  USS5        U R                  U R                  USS5        U R                  U R                  USS5        g )	Nr   )add_without_sigr5   r6         @r8   g333333@abc)abc)r9   r=   r   r1   )r   r=   s     r   test_call_without_sig,TestDispatcherPickling.test_call_without_sig:   sM    7!VL#zR%Ur   c                     SSK Jn  U R                  U R                  USS5        U R                  U R                  U[        [        5       [        5       45        g )Nr   )add_nopythonr>   r?   )r9   rF   r   r1   r   object)r   rF   s     r   test_call_nopython)TestDispatcherPickling.test_call_nopythonA   s@    4sJO{VXW]W_L`ar   c                 T    SSK Jn  U R                  U R                  U[        S5        g )Nr   )add_nopython_fail)r      )r9   rK   r   r1   r   )r   rK   s     r   test_call_nopython_fail.TestDispatcherPickling.test_call_nopython_failG   s    91BKQWXr   c                 L    SSK Jn  U R                  U R                  USS5        g )Nr   )get_global_objmodeg      @)g      @)r9   rP   r   r1   )r   rP   s     r   test_call_objmode_with_global4TestDispatcherPickling.test_call_objmode_with_globalL   s    :1CS&Qr   c                 \    SSK Jn  U" S5      nU R                  U R                  USS5        g )Nr   closure   )rL      )r9   rU   r   r1   )r   rU   inners      r   test_call_closure(TestDispatcherPickling.test_call_closureP   s&    /
6Br   c                 \    SSK Jn  U" S0 UD6nU R                  U R                  USS5        g )Nr   )closure_with_globalsg      @      @)      @)r9   r\   r   r1   )r   jit_argsr\   rX   s       r   check_call_closure_with_globals6TestDispatcherPickling.check_call_closure_with_globalsU   s*    <$5H5VDr   c                 "    U R                  SS9  g )NT)nopythonra   r   s    r   'test_call_closure_with_globals_nopython>TestDispatcherPickling.test_call_closure_with_globals_nopythonZ       ,,d,;r   c                 "    U R                  SS9  g )NT)forceobjre   rf   s    r   &test_call_closure_with_globals_objmode=TestDispatcherPickling.test_call_closure_with_globals_objmode]   ri   r   c                 \    SSK Jn  U" S5      nU R                  U R                  USS5        g )Nr   )closure_calling_other_functionr_   g      &@)r^   g      @)r9   ro   r   r1   )r   ro   rX   s      r   (test_call_closure_calling_other_function?TestDispatcherPickling.test_call_closure_calling_other_function`   s'    F.s3jIr   c                 \    SSK Jn  U" S5      nU R                  U R                  USS5        g )Nr   closure_calling_other_closurer_   g       @r]   )r9   rt   r   r1   )r   rt   rX   s      r   'test_call_closure_calling_other_closure>TestDispatcherPickling.test_call_closure_calling_other_closuree   s'    E-c2VDr   c                 L    SSK Jn  U R                  U R                  USS5        g )Nr   )dyn_func$   rV   )r9   rx   r   r1   )r   rx   s     r   test_call_dyn_func)TestDispatcherPickling.test_call_dyn_funcj   s    02tDr   c                 L    SSK Jn  U R                  U R                  USS5        g )Nr   )dyn_func_objmodery   rz   )r9   r~   r   r1   )r   r~   s     r   test_call_dyn_func_objmode1TestDispatcherPickling.test_call_dyn_func_objmodeo   s    81A2tLr   c                 \    SSK Jn  U" S5      nU R                  U R                  UUS5        g )Nr   )get_renamed_module        )r   )r9   r   r   r1   )r   r   expecteds      r   test_renamed_module*TestDispatcherPickling.test_renamed_modulet   s-    : &c*1C (&	2r   c                     SSK Jn  U" S5      n[        R                  " U5      nSR                  " S0 [        5       D6n[        R                  " [        R                  SU/5        g)ze
Check that reconstructing doesn't depend on resources already
instantiated in the original process.
r   rs   r_   zif 1:
            import pickle

            data = {pickled!r}
            func = pickle.loads(data)
            res = func(4.0)
            assert res == 8.0, res
            -cN )
r9   rt   r   r   formatlocals
subprocessr1   sys
executable)r   rt   r+   r/   codes        r   test_other_process)TestDispatcherPickling.test_other_process|   s_    
 	F,S1,,t$  #  # 	s~~tT:;r   c                 ~   SSK Jn  U" S5      n[        R                  " U5      nU" S5      n[        R                  " U5      n[        R                  " U5      n[        R                  " U5      n[        R                  " U5      nU R                  Xg5        U R                  U" SS5      S5        UR                  5         U R                  U" SS5      S	5        U R                  Xh5        U R                  U" SS5      S	5        U" S
5      nU" SS5        [        R                  " U5      nA[        R                  " 5         [        R                  " U5      n[        R                  " U5      nU R                  Xg5        U R                  U" SS5      S5        UR                  5         U R                  U" SS5      S5        g)z
Check that deserializing the same function multiple times re-uses
the same dispatcher object.

Note that "same function" is intentionally under-specified.
r   rT   r5   rV   rL   rW   
   r7         *   +         N)r9   rU   r   r   r	   assertIsassertEqualdisable_compileassertIsNotgccollect)	r   rU   r+   r/   func2pickled2fghs	            r   
test_reuse!TestDispatcherPickling.test_reuse   sU    	0qz,,t$
<<&LL!LL!LL"a1a"%	1a"%1a"% qzR,,t$


LL!LL!a1a"%	1a"%r   c                 V    Sn[         R                  " [        R                  SU/5        g)z>
The imp module was deprecated in v3.4 in favour of importlib
a  if 1:
            import pickle
            import warnings
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always', DeprecationWarning)
                from numba import njit
                @njit
                def foo(x):
                    return x + 1
                foo(1)
                serialized_foo = pickle.dumps(foo)
            for x in w:
                if 'serialize.py' in x.filename:
                    assert "the imp module is deprecated" not in x.msg
        r   N)r   r1   r   r   )r   r   s     r   test_imp_deprecation+TestDispatcherPickling.test_imp_deprecation   s$     	s~~tT:;r   r   N)__name__
__module____qualname____firstlineno__r   
contextlibcontextmanagerr"   r1   r:   rC   rH   rM   rQ   rY   ra   rg   rl   rp   ru   r{   r   r   r   r   r   __static_attributes__r   r   r   r   r      s    ) 3 3#NVbY
RC
E
<<J
E
E
M
2<$$&L<r   r   c                       \ rS rSrS rSrg)TestSerializationMisc   c                     SSK Jn  [        5       n[        R                  " U5      n[        U5      nU" [        U5      X45      nU R                  XR5        U" [        U5      X45      nU R                  XV5        g )Nr   )_numba_unpickle)	numba.core.serializer   rG   r   r   hashidr   r   )r   r   
random_objbytebufhashedgot1got2s          r   test_numba_unpickle)TestSerializationMisc.test_numba_unpickle   s^    8X
,,z*j!r*~w?*r*~w?d!r   r   N)r   r   r   r   r   r   r   r   r   r   r      s    "r   r   c                   f    \ rS rSrSrSrS r\R                  " \ S:H  S5      S 5       r	S r
S	 rS
rg)TestCloudPickleIssues   zOThis test case includes issues specific to the cloudpickle implementation.
    Fc                    ^ ^  " S S5      mU4S jnUU 4S jn[        T5      nU" 5         U" 5         [        U5        U" 5         [        U5        U" 5         g )Nc                       \ rS rSrSrSrg)ITestCloudPickleIssues.test_dynamic_class_reset_on_unpickle.<locals>.Klass   Nr   r   r   r   r   classvarr   r   r   r   Klassr          Hr   r   c                     > ST l         g Nd   )r   r   s   r   mutatorKTestCloudPickleIssues.test_dynamic_class_reset_on_unpickle.<locals>.mutator   s
     ENr   c                  >   > TR                  T R                  S5        g r   )r   r   )r   r   s   r   checkITestCloudPickleIssues.test_dynamic_class_reset_on_unpickle.<locals>.check   s    U^^S1r   r   )r   r   r   savedr   s   `   @r   $test_dynamic_class_reset_on_unpickle:TestCloudPickleIssues.test_dynamic_class_reset_on_unpickle   sD    	 		!	2 e	eer   __main__z*Test cannot run as when module is __main__c                     [        S5      nUR                  [        S9nUR                  5         UR	                  SS9  U R                  UR                  S5        g )Nspawn)target<   timeoutr   )r   Process"check_main_class_reset_on_unpicklestartjoinr   exitcode)r   mpprocs      r   !test_main_class_reset_on_unpickle7TestCloudPickleIssues.test_main_class_reset_on_unpickle   sJ     !zz!CzD

		"	*r   c                      " S S5      n[        U5      n[        S5      nUR                  [        U4S9nUR	                  5         UR                  SS9  U R                  UR                  S5        g )Nc                       \ rS rSrSrSrg)RTestCloudPickleIssues.test_dynamic_class_reset_on_unpickle_new_proc.<locals>.Klass   Nr   r   r   r   r   r   r      r   r   r   r   )r   r   r   r   r   )r   r   r   !check_unpickle_dyn_class_new_procr   r   r   r   )r   r   r   r   r   s        r   -test_dynamic_class_reset_on_unpickle_new_procCTestCloudPickleIssues.test_dynamic_class_reset_on_unpickle_new_proc   sc    	 	 e !zz!B%zR

		"	*r   c                 f    [         R                  " [        5      nU R                  U" 5       S5        g )N)r   r   )numbanjit
issue_7356r   )r   cfuncs     r   test_dynamic_class_issue_73563TestCloudPickleIssues.test_dynamic_class_issue_7356  s"    

:&*-r   r   N)r   r   r   r   __doc___numba_parallel_test_r   unittestskipIfr   r   r   r   r   r   r   r   r      sE    !( __X+AC+C++.r   r   c                       \ rS rSrSrSrg)DynClassi  Nr   )r   r   r   r   rA   r   r   r   r   r   r     s    Ar   r   c                     [         R                  " SS9   S[        l        [        R                  n S S S 5        [         R                  " SS9   [        R                  nS S S 5        W U4$ ! , (       d  f       N?= f! , (       d  f       W W4$ = f)Nintp)beforer   )after)r   objmoder   rA   )r   r   s     r   r   r     se    	f	%
 
& 
V	$

 
%5= 
&	% 
%	$5=s   A*A;*
A8;
Bc                      [         R                  " SSS9n U S   nUR                  S:X  d   eUR                  S:w  d   e[	        U5      nSUl        [        X5        g )Nz"numba.tests.cloudpickle_main_classr   )run_namer   r   )runpy
run_moduler   r   r   _check_dyn_class)glbsr   r   s      r   r   r     sa    ,D
 MEz)))>>S   %LEENU"r   c                 b    [        U 5      nUR                  S:w  d   eSUl        [        X5        g r   )r	   r   r  )r   r   s     r   r   r   0  s,    %LE>>S   ENU"r   c                    ^  U 4S jnU" 5         [        U5      nUT La  [        S5      eU" 5         [        U5      nUT La  [        S5      eU" 5         g )Nc                  <   > T R                   S:w  a  [        S5      eg )Nr   zCheck failed. Klass reset.)r   AssertionErrorr   s   r   r   _check_dyn_class.<locals>.check:  s     >>S  !=>> !r   zExpected reuse)r	   r	  )r   r   r   loadeds   `   r   r  r  9  sS    ? 
G5\FU-..	G5\FU-..	Gr   r   )r   r   r   r  r   r   r   multiprocessingr   r   numba.core.errorsr   numba.tests.supportr   numba.core.target_extensionr   numba.cloudpickler   r	   r   r   r   rG   r   r   r   r   r  r   mainr   r   r   <module>r     s     	    
  '  ) ( C *v<X v<r"H ""3.H 3.lv 
#"#" zMMO r   