
    dafٌ                        d dl Z d dlmZmZmZmZmZ 	 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Zd dlZ G d de      Z G d de j$                        Ze G d de j$                               Z G d	 d
e j$                        Z G d de      Z G d de      Z G d de      Z G d de      Zd Zd Z G d d      Z e       Z e       Z G d de j$                        Z dZ!dZ"d Z#d Z$dZ% G d de j$                        Z& G d  d!      Z'e G d" d#e j$                               Z(e G d$ d%e j$                               Z) G d& d'e j$                        Z*e+d(k(  r e jX                          yy# e$ r dZY `w xY w))    N)cpython_onlyrequires_limited_apiskip_on_s390xis_wasiPy_DEBUGc                       e Zd Zd Zd Zy)BadStrc                      y)NT )selfothers     )/root/Python-3.12.4/Lib/test/test_call.py__eq__zBadStr.__eq__   s        c                 2    t         j                  |       dz  S )N   )str__hash__r   s    r   r   zBadStr.__hash__   s    ||D!A%%r   N)__name__
__module____qualname__r   r   r   r   r   r	   r	      s    &r   r	   c                       e Zd Zd Zd Zy)FunctionCallsc                    t        j                  ddg      }|j                  d       t        |j	                               }d } |di |}| j                  |t               | j                  t        |j	                               |       y )N)a   )b   r   c                      | S Nr   )kws    r   fnz+FunctionCalls.test_kwargs_order.<locals>.fn    s    Ir   r   )collectionsOrderedDictmove_to_endlistitemsassertIsInstancedictassertEqual)r   odexpectedr#   ress        r   test_kwargs_orderzFunctionCalls.test_kwargs_order   sp    $$h%9:
s
#	 h2hc4(ciik*H5r   c                 Z    d }t        d      D ]  }	  |d         y # t        $ r Y w xY w)Nc                       y r!   r   r   r   r   fzBFunctionCalls.test_frames_are_popped_after_failed_calls.<locals>.f*   s    r     )range	TypeError)r   r2   _s      r   )test_frames_are_popped_after_failed_callsz7FunctionCalls.test_frames_are_popped_after_failed_calls'   s:    	t 	A$	  s   	**N)r   r   r   r/   r7   r   r   r   r   r      s    6	r   r   c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+y*)+CFunctionCallsErrorMessagesc                 J    d}| j                  t        |i j                         y )Nz7__contains__\(\) takes exactly one argument \(0 given\)assertRaisesRegexr5   __contains__r   msgs     r   test_varargs0z)CFunctionCallsErrorMessages.test_varargs07   s    Hy#r?r   c                 N    d}| j                  t        |i j                  dd       y )Nz7__contains__\(\) takes exactly one argument \(2 given\)r   r   r;   r>   s     r   test_varargs2z)CFunctionCallsErrorMessages.test_varargs2;   s!    Hy#r1Er   c                 X    d}| j                  t        |t        j                  ddd       y )Nz@^from_bytes\(\) takes at most 2 positional arguments \(3 given\)   alittleF)r<   r5   int
from_bytesr>   s     r   test_varargs3z)CFunctionCallsErrorMessages.test_varargs3?   s#    Qy#s~~tXuUr   c                     d}| j                  t        |i j                         d}| j                  t        |i j                         y )Nz'get expected at least 1 argument, got 0zexpected 1 argument, got 0)r<   r5   get__delattr__r>   s     r   test_varargs1minz,CFunctionCallsErrorMessages.test_varargs1minC   s8    8y#rvv6+y#r~~>r   c                 >    d}| j                  t        |t               y )Nz,getattr expected at least 2 arguments, got 0r<   r5   getattrr>   s     r   test_varargs2minz,CFunctionCallsErrorMessages.test_varargs2minJ   s    =y#w7r   c                 B    d}| j                  t        |t        dd       y )Nz(input expected at most 1 argument, got 2r   r   )r<   r5   inputr>   s     r   test_varargs1maxz,CFunctionCallsErrorMessages.test_varargs1maxN   s    9y#ua;r   c                 P    d}| j                  t        |i j                  ddd       y )Nz'get expected at most 2 arguments, got 3r   r   r   )r<   r5   rJ   r>   s     r   test_varargs2maxz,CFunctionCallsErrorMessages.test_varargs2maxR   s#    8y#rvvq!Q?r   c                 N    d}| j                  t        |i j                  d       y )N+__contains__\(\) takes no keyword argumentsr   xr;   r>   s     r   test_varargs1_kwz,CFunctionCallsErrorMessages.test_varargs1_kwV   s"    <y#r!Dr   c                 P    d}| j                  t        |i j                  dd       y )NrW   r   rY   yr;   r>   s     r   test_varargs2_kwz,CFunctionCallsErrorMessages.test_varargs2_kwZ   s$    <y#r!qIr   c                 B    d}| j                  t        |t        d       y )Nz#bool\(\) takes no keyword argumentsr   rX   )r<   r5   boolr>   s     r   test_varargs3_kwz,CFunctionCallsErrorMessages.test_varargs3_kw^   s    4y#tq9r   c                 N    d}| j                  t        |g j                  d       y )Nz-^list[.]index\(\) takes no keyword arguments$r   rX   )r<   r5   indexr>   s     r   test_varargs4_kwz,CFunctionCallsErrorMessages.test_varargs4_kwb   s"    >y#rxx1=r   c                 B    d}| j                  t        |t        d       y )Nz(^hasattr\(\) takes no keyword arguments$r   rX   )r<   r5   hasattrr>   s     r   test_varargs5_kwz,CFunctionCallsErrorMessages.test_varargs5_kwf       9y#w!<r   c                 B    d}| j                  t        |t        d       y )Nz(^getattr\(\) takes no keyword arguments$r   rX   rN   r>   s     r   test_varargs6_kwz,CFunctionCallsErrorMessages.test_varargs6_kwj   rh   r   c                 B    d}| j                  t        |t        d       y )Nz%^next\(\) takes no keyword arguments$r   rX   )r<   r5   nextr>   s     r   test_varargs7_kwz,CFunctionCallsErrorMessages.test_varargs7_kwn   s    6y#tq9r   c                 V    d}| j                  t        |t        j                  d       y )Nz/^_struct[.]pack\(\) takes no keyword arguments$r   rX   )r<   r5   structpackr>   s     r   test_varargs8_kwz,CFunctionCallsErrorMessages.test_varargs8_kwr   s"    @y#v{{a@r   c                 V    d}| j                  t        |t        j                  d       y )Nz4^_struct[.]pack_into\(\) takes no keyword arguments$r   rX   )r<   r5   ro   	pack_intor>   s     r   test_varargs9_kwz,CFunctionCallsErrorMessages.test_varargs9_kwv   s$    Ey#v/?/?1Er   c                 r    d}| j                  t        |t        j                         j                  d       y )Nz.^deque[.]index\(\) takes no keyword arguments$r   rX   )r<   r5   r$   dequerc   r>   s     r   test_varargs10_kwz-CFunctionCallsErrorMessages.test_varargs10_kwz   s-    ?y#{/@/@/B/H/HANr   c                     d}| j                  t        |t        j                  j                  t        j                  d      d       y )Nz.^Struct[.]pack\(\) takes no keyword arguments$ r   rX   )r<   r5   ro   Structrp   r>   s     r   test_varargs11_kwz-CFunctionCallsErrorMessages.test_varargs11_kw~   s5    ?y#v}}/A/A6==QSCTXYZr   c                 J    d}| j                  t        |t        t               y )Nz-^staticmethod\(\) takes no keyword arguments$func)r<   r5   staticmethodidr>   s     r   test_varargs12_kwz-CFunctionCallsErrorMessages.test_varargs12_kw   s    >y#|"Er   c                 J    d}| j                  t        |t        t               y )Nz,^classmethod\(\) takes no keyword arguments$r}   )r<   r5   classmethodr   r>   s     r   test_varargs13_kwz-CFunctionCallsErrorMessages.test_varargs13_kw   s    =y#{Dr   c                 Z    d}| j                  t        |t        j                  ddd       y )Nz:^product\(\) takes at most 1 keyword argument \(2 given\)$r   r   r   )repeatfoo)r<   r5   	itertoolsproductr>   s     r   test_varargs14_kwz-CFunctionCallsErrorMessages.test_varargs14_kw   s.    Ky#(00!A1 	 	Fr   c           
      J    d}| j                  t        |t        ddddd       y )Nz?^ImportError\(\) takes at most 3 keyword arguments \(4 given\)$r   r   r   r   )namepath	name_fromr   )r<   r5   ImportErrorr>   s     r   test_varargs15_kwz-CFunctionCallsErrorMessages.test_varargs15_kw   s-    Py#*AAAPQ 	 	Sr   c           	      H    d}| j                  t        |t        dddd       y )Nz7^min\(\) takes at most 2 keyword arguments \(3 given\)$r   r   r   r   )defaultkeyr   )r<   r5   minr>   s     r   test_varargs16_kwz-CFunctionCallsErrorMessages.test_varargs16_kw   s*    Hy#"AqaQ 	 	@r   c                 L    d}| j                  t        |t        dddddd	       y )	Nz3'foo' is an invalid keyword argument for print\(\)$r   r   r   r         )sependfileflushr   )r<   r5   printr>   s     r   test_varargs17_kwz-CFunctionCallsErrorMessages.test_varargs17_kw   s.    Dy#$aQAAQA 	 	Or   c                     d}| j                  t        |      5  t        di t        d      di d d d        y # 1 sw Y   y xY w)Nz'invalid keyword argument for print\(\)$r   ,)r   r   )r<   r5   r   r	   r>   s     r   test_varargs18_kwz-CFunctionCallsErrorMessages.test_varargs18_kw   s@    8##Is3 	0/6%=#./	0 	0 	0	   9Ac                     d}| j                  t        |      5  t        di t        d      di d d d        y # 1 sw Y   y xY w)Nz'invalid keyword argument for round\(\)$r   r   )g      ?)r<   r5   roundr	   r>   s     r   test_varargs19_kwz-CFunctionCallsErrorMessages.test_varargs19_kw   s@    8##Is3 	.-6%=!,-	. 	. 	.r   c                 L    d}| j                  t        |i j                  d       y )Nz'keys\(\) takes no arguments \(1 given\)r   r<   r5   keysr>   s     r   test_oldargs0_1z+CFunctionCallsErrorMessages.test_oldargs0_1   s    8y#rww:r   c                 N    d}| j                  t        |i j                  dd       y )Nz'keys\(\) takes no arguments \(2 given\)r   r   r   r>   s     r   test_oldargs0_2z+CFunctionCallsErrorMessages.test_oldargs0_2   s!    8y#rww1=r   c                 N    d}| j                  t        |i j                  d       y )N#keys\(\) takes no keyword argumentsr   rX   r   r>   s     r   test_oldargs0_1_kwz.CFunctionCallsErrorMessages.test_oldargs0_1_kw   s"    4y#rww!<r   c                 P    d}| j                  t        |i j                  dd       y )Nr   r   r\   r   r>   s     r   test_oldargs0_2_kwz.CFunctionCallsErrorMessages.test_oldargs0_2_kw   s$    4y#rww!qAr   c                 J    d}| j                  t        |g j                         y )Nz0count\(\) takes exactly one argument \(0 given\)r<   r5   countr>   s     r   test_oldargs1_0z+CFunctionCallsErrorMessages.test_oldargs1_0   s    Ay#rxx8r   c                 N    d}| j                  t        |g j                  dd       y )Nz0count\(\) takes exactly one argument \(2 given\)r   r   r   r>   s     r   test_oldargs1_2z+CFunctionCallsErrorMessages.test_oldargs1_2   s!    Ay#rxxA>r   c                 N    d}| j                  t        |g j                  d       y N$count\(\) takes no keyword argumentsr   rX   r   r>   s     r   test_oldargs1_0_kwz.CFunctionCallsErrorMessages.test_oldargs1_0_kw   s"    5y#rxx1=r   c                 P    d}| j                  t        |g j                  i d       y r   r   r>   s     r   test_oldargs1_1_kwz.CFunctionCallsErrorMessages.test_oldargs1_1_kw   s$    5y#rxxqAr   c                 P    d}| j                  t        |g j                  dd       y )Nr   r   r\   r   r>   s     r   test_oldargs1_2_kwz.CFunctionCallsErrorMessages.test_oldargs1_2_kw   s$    5y#rxx1Br   c                 F    d}| j                  t        |t                      y )Nz!^'object' object is not callable$)r<   r5   objectr>   s     r   test_object_not_callablez4CFunctionCallsErrorMessages.test_object_not_callable   s    2y#vx8r   c                 \    d}| j                  t        |t        j                  d             y N!^'module' object is not callable$mod)r<   r5   types
ModuleTyper>   s     r   (test_module_not_callable_no_suggestion_0zDCFunctionCallsErrorMessages.test_module_not_callable_no_suggestion_0   s$    2y#u/?/?/FGr   c                 n    d}t        j                  d      }d|_        | j                  t        ||       y Nr   r   *   r   r   r   r<   r5   r   r?   r   s      r   (test_module_not_callable_no_suggestion_1zDCFunctionCallsErrorMessages.test_module_not_callable_no_suggestion_1   s0    2u%y#s3r   c                 d    d}t        j                  d      }|`| j                  t        ||       y r   r   r   r   r<   r5   r   s      r   (test_module_not_callable_no_suggestion_2zDCFunctionCallsErrorMessages.test_module_not_callable_no_suggestion_2   s.    2u%Ly#s3r   c                 n    d}t        j                  d      }d|_        | j                  t        ||       y r   r   r   s      r   (test_module_not_callable_no_suggestion_3zDCFunctionCallsErrorMessages.test_module_not_callable_no_suggestion_3   s0    2u%y#s3r   c                 p    d}t        j                  d      }d |_        | j                  t        ||       y )NzH^'module' object is not callable\. Did you mean: 'mod\.mod\(\.\.\.\)'\?$r   c                       y)N.r   r   r   r   <lambda>zQCFunctionCallsErrorMessages.test_module_not_callable_suggestion.<locals>.<lambda>       r   r   r   s      r   #test_module_not_callable_suggestionz?CFunctionCallsErrorMessages.test_module_not_callable_suggestion   s0    Yu%y#s3r   N),r   r   r   r@   rB   rH   rL   rP   rS   rU   rZ   r^   ra   rd   rg   rj   rm   rq   rt   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9   r9   4   s    @FV?8<@EJ:>==:AFO[FEF
S
@
O
0.;>=B9?>BC9H4444r   r9   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestCallingConventionsa  Test calling using various C calling conventions (METH_*) from Python

    Subclasses test several kinds of functions (module-level, methods,
    class methods static methods) using these attributes:
      obj: the object that contains tested functions (as attributes)
      expected_self: expected "self" argument to the C function

    The base class tests module-level functions.
    c                 (    t         x| _        | _        y r!   )	_testcapiobjexpected_selfr   s    r   setUpzTestCallingConventions.setUp   s    (114%r   c                 v    | j                  | j                  j                  ddd      | j                  df       y Nr   r   r   r   r   r   r+   r   meth_varargsr   r   s    r   test_varargsz#TestCallingConventions.test_varargs   s4    HH!!!Q*+	
r   c                 n    | j                   | j                  j                  d | j                  df       y Nr   r   r   s    r   test_varargs_extz'TestCallingConventions.test_varargs_ext  s2    !DHH!!9-+	
r   c                 >     d} j                  t        | fd       y )Nz+meth_varargs\(\) takes no keyword argumentsc                  <     j                   j                  d      S Nr   )k)r   r   r   s   r   r   z>TestCallingConventions.test_varargs_error_kw.<locals>.<lambda>  s    DHH$9$9A$9$> r   r<   r5   r>   s   ` r   test_varargs_error_kwz,TestCallingConventions.test_varargs_error_kw	  s    <s>	
r   c                     | j                  | j                  j                  dddd      | j                  ddddf       y Nr   r   r   r   r   r   r   r   r+   r   meth_varargs_keywordsr   r   s    r   test_varargs_keywordsz,TestCallingConventions.test_varargs_keywords  s@    HH**1a1*:qq)9:	
r   c           	          | j                   | j                  j                  ddgi ddd| j                  ddddf       y r   r   r   s    r   test_varargs_keywords_extz0TestCallingConventions.test_varargs_keywords_ext  sG    *DHH**QFGAA6FGqq)9:	
r   c                 r    | j                  | j                  j                  d      | j                  df       y Nr   r+   r   meth_or   r   s    r   test_ozTestCallingConventions.test_o  s*    +d.@.@!-DEr   c                 p    | j                   | j                  j                  dg | j                  df       y r   r   r   s    r   
test_o_extz!TestCallingConventions.test_o_ext  s.    1#.1C1CQ0GHr   c                 ^    d}| j                  t        || j                  j                         y )Nz1meth_o\(\) takes exactly one argument \(0 given\))r<   r5   r   r   r>   s     r   test_o_error_no_argz*TestCallingConventions.test_o_error_no_arg!  s!    By#txx?r   c                 >     d} j                  t        | fd       y )Nz1meth_o\(\) takes exactly one argument \(2 given\)c                  <     j                   j                  dd      S Nr   r   r   r   r   s   r   r   z>TestCallingConventions.test_o_error_two_args.<locals>.<lambda>(  s    DHHOOAq$9 r   r   r>   s   ` r   test_o_error_two_argsz,TestCallingConventions.test_o_error_two_args%  s    Bs9	
r   c                 >     d} j                  t        | fd       y )Nz1meth_o\(\) takes exactly one argument \(3 given\)c                  6      j                   j                  d S r   r  r   s   r   r   z9TestCallingConventions.test_o_error_ext.<locals>.<lambda>.  s    ODHHOOY$? r   r   r>   s   ` r   test_o_error_extz'TestCallingConventions.test_o_error_ext+  s    Bs?	
r   c                 >     d} j                  t        | fd       y )N%meth_o\(\) takes no keyword argumentsc                  <     j                   j                  d      S r   r  r   s   r   r   z8TestCallingConventions.test_o_error_kw.<locals>.<lambda>4      DHHOOaO$8 r   r   r>   s   ` r   test_o_error_kwz&TestCallingConventions.test_o_error_kw1      6s8	
r   c                 >     d} j                  t        | fd       y )Nr
  c                  <     j                   j                  d      S r   r  r   s   r   r   z<TestCallingConventions.test_o_error_arg_kw.<locals>.<lambda>:  r  r   r   r>   s   ` r   test_o_error_arg_kwz*TestCallingConventions.test_o_error_arg_kw7  r  r   c                 l    | j                  | j                  j                         | j                         y r!   r+   r   meth_noargsr   r   s    r   test_noargsz"TestCallingConventions.test_noargs=  s%    --/1C1CDr   c                 j    | j                   | j                  j                  g  | j                         y r!   r  r   s    r   test_noargs_extz&TestCallingConventions.test_noargs_ext@  s*    ---r2D4F4FGr   c                 >     d} j                  t        | fd       y )Nz.meth_noargs\(\) takes no arguments \(1 given\)c                  :     j                   j                  d      S r   r   r  r   s   r   r   z>TestCallingConventions.test_noargs_error_arg.<locals>.<lambda>F  s    DHH$8$8$; r   r   r>   s   ` r   test_noargs_error_argz,TestCallingConventions.test_noargs_error_argC  s    ?s;	
r   c                 >     d} j                  t        | fd       y )Nz.meth_noargs\(\) takes no arguments \(2 given\)c                  <     j                   j                  dd      S r  r  r   s   r   r   z?TestCallingConventions.test_noargs_error_arg2.<locals>.<lambda>L  s    DHH$8$8A$> r   r   r>   s   ` r   test_noargs_error_arg2z-TestCallingConventions.test_noargs_error_arg2I  s    ?s>	
r   c                 >     d} j                  t        | fd       y )Nz.meth_noargs\(\) takes no arguments \(3 given\)c                  6      j                   j                  d S r   r  r   s   r   r   z>TestCallingConventions.test_noargs_error_ext.<locals>.<lambda>R  s    $8DHH$8$8)$D r   r   r>   s   ` r   test_noargs_error_extz,TestCallingConventions.test_noargs_error_extO  s    ?sD	
r   c                 >     d} j                  t        | fd       y )Nz*meth_noargs\(\) takes no keyword argumentsc                  <     j                   j                  d      S r   r  r   s   r   r   z=TestCallingConventions.test_noargs_error_kw.<locals>.<lambda>X  s    DHH$8$81$8$= r   r   r>   s   ` r   test_noargs_error_kwz+TestCallingConventions.test_noargs_error_kwU  s    ;s=	
r   c                 v    | j                  | j                  j                  ddd      | j                  df       y r   r+   r   meth_fastcallr   r   s    r   test_fastcallz$TestCallingConventions.test_fastcall[  s4    HH""1a++	
r   c                 n    | j                   | j                  j                  d | j                  df       y r   r&  r   s    r   test_fastcall_extz(TestCallingConventions.test_fastcall_exta  s2    "DHH""I.+	
r   c                 >     d} j                  t        | fd       y )Nz,meth_fastcall\(\) takes no keyword argumentsc                  <     j                   j                  d      S r   )r   r'  r   s   r   r   z?TestCallingConventions.test_fastcall_error_kw.<locals>.<lambda>j  s    DHH$:$:Q$:$? r   r   r>   s   ` r   test_fastcall_error_kwz-TestCallingConventions.test_fastcall_error_kwg  s    =s?	
r   c                     | j                  | j                  j                  dddd      | j                  ddddf       y r   r+   r   meth_fastcall_keywordsr   r   s    r   test_fastcall_keywordsz-TestCallingConventions.test_fastcall_keywordsm  s@    HH++AqA+;qq)9:	
r   c           	          | j                   | j                  j                  di ddd| j                  ddddf       y )Nr   r   r   r   r/  r   s    r   test_fastcall_keywords_extz1TestCallingConventions.test_fastcall_keywords_exts  sC    +DHH++VHQQ7GHqq)9:	
r   N)r   r   r   __doc__r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r!  r$  r(  r*  r-  r1  r3  r   r   r   r   r      s    2




FI@



EH








r   r   c                       e Zd ZdZd Zy)TestCallingConventionsInstancez?Test calling instance methods using various calling conventionsc                 D    t        j                         x| _        | _        y r!   )r   MethInstancer   r   r   s    r   r   z$TestCallingConventionsInstance.setUp}  s    (1(>(>(@@4%r   Nr   r   r   r4  r   r   r   r   r6  r6  z  s    IAr   r6  c                       e Zd ZdZd Zy)TestCallingConventionsClassz<Test calling class methods using various calling conventionsc                 <    t         j                  x| _        | _        y r!   r   	MethClassr   r   r   s    r   r   z!TestCallingConventionsClass.setUp  s    (1(;(;;4%r   Nr9  r   r   r   r;  r;    s
    F<r   r;  c                       e Zd ZdZd Zy)#TestCallingConventionsClassInstancez&Test calling class methods on instancec                 `    t        j                         | _        t         j                  | _        y r!   r=  r   s    r   r   z)TestCallingConventionsClassInstance.setUp  s     &&(&00r   Nr9  r   r   r   r@  r@    s
    01r   r@  c                       e Zd ZdZd Zy)TestCallingConventionsStaticz=Test calling static methods using various calling conventionsc                 D    t        j                         | _        d | _        y r!   )r   
MethStaticr   r   r   s    r   r   z"TestCallingConventionsStatic.setUp  s    '')!r   Nr9  r   r   r   rC  rC    s
    G"r   rC  c                 
    | |gS r!   r   arg1arg2s     r   pyfuncrJ    s    $<r   c                       yNnoargr   r   r   r   pyfunc_noargrN    s    r   c                   8    e Zd Zd Zd Zed        Zed        Zy)PythonClassc                 
    ||gS r!   r   )r   rH  rI  s      r   methodzPythonClass.method  s    d|r   c                      yrL  r   r   s    r   method_noargzPythonClass.method_noarg  s    r   c                      y)Nr   r   )clss    r   class_methodzPythonClass.class_method  s    r   c                       y)Nr   r   r   r   r   static_methodzPythonClass.static_method  s    r   N)	r   r   r   rR  rT  r   rW  r   rY  r   r   r   rP  rP    s4        r   rP  c                   n   e Zd ZdZedddgfeddfej                  ddfej                  ddfe	j                  dddgfe	j                  ddfe	j                  ddfe	j                  ddfgZed	d
diddgfeddddddgfe	j                  d	d
diddgfe	j                  ddddddgfgZ ej                         Zeefeefej"                  ej"                  f ej"                         ej"                  fej$                  dffD ]%  \  ZZej+                  ej,                  dedffej.                  dedeffej2                  dedffej2                  dedffej4                  dedeffej4                  dedeffej6                  defej8                  dedffg       ej+                  ej.                  dddiedddiffej.                  dddiedddiffej.                  di edeffej4                  dddiedddiffej4                  dddiedddiffej4                  di edeffg       ( d Zd Zd Zd Z d Z!y)FastCallTestsz0Test calling using various callables from C
    r   r   r   r   rM  r   r   )r   rI  rG  N){   r\  rY   r]   c                     t        |t              r!|d   t        u r|d   i d fv rg |d d |d   }| j                  ||       y )N)
isinstancetupleNULL_OR_EMPTYr+   )r   resultr-   s      r   check_resultzFastCallTests.check_result  sP    h&8B<=+Hbzb$Z'7Xcr]7F2J7*r   c                 "   | j                   D ]t  \  }}}| j                  ||      5  t        j                  ||      }| j	                  ||       |s(t        j                  |d       }| j	                  ||       d d d        v y # 1 sw Y   xY w)Nr~   args)CALLS_POSARGSsubTestr   pyobject_fastcallrc  )r   r~   rf  r-   rb  s        r   r(  zFastCallTests.test_fastcall
  s     %)$6$6 	8 D$4d3 8"44T4@!!&(3&88tDF%%fh78 8	88 8s   ABB	c                    | j                   D ]v  \  }}}| j                  ||      5  t        j                  ||d       }| j	                  ||       |s)t        j                  |d d       }| j	                  ||       d d d        x | j
                  D ]M  \  }}}}| j                  |||      5  t        j                  |||      }| j	                  ||       d d d        O y # 1 sw Y   xY w# 1 sw Y   fxY w)Nre  r~   rf  kwargs)rg  rh  r   pyobject_fastcalldictrc  CALLS_KWARGS)r   r~   rf  r-   rb  rl  s         r   test_vectorcall_dictz"FastCallTests.test_vectorcall_dict  s    %)$6$6 		8 D$4d3 8"88tTJ!!&(3&<<T4NF%%fh78 8		8 -1,=,= 	4(D$4d6B 4"88tVL!!&(34 4	48 84 4s   AC#.*C/#C,	/C8	c                    | j                   D ]  \  }}}| j                  ||      5  t        j                  ||d       }| j	                  ||       t        j                  ||d      }| j	                  ||       |sRt        j                  |d d       }| j	                  ||       t        j                  |d d      }| j	                  ||       d d d         | j
                  D ]  \  }}}}| j                  |||      5  t        |j                               }|t        |j                               z   }t        j                  |||      }| j	                  ||       d d d         y # 1 sw Y   gxY w# 1 sw Y   xY w)Nre  r   rk  )	rg  rh  r   pyobject_vectorcallrc  rn  r`  r   values)r   r~   rf  r-   rb  rl  kwnamess          r   test_vectorcallzFastCallTests.test_vectorcall*  sv    %)$6$6 	8 D$4d3 8"66tT4H!!&(3 #66tT2F!!&(3&::4tLF%%fh7 '::4rJF%%fh7!8 8	8& -1,=,= 	4(D$4d6B 4.eFMMO44"66tT7K!!&(3	4 4	4%8 8&4 4s   B'E* AE7*E4	7F 	c                 f     G d d      } | |             }t        ddd|fi |j                   y )Nc                       e Zd ZdgZd Zd Zy)>FastCallTests.test_fastcall_clearing_dict.<locals>.IntWithDictrl  c                     || _         y r!   )rl  )r   rl  s     r   __init__zGFastCallTests.test_fastcall_clearing_dict.<locals>.IntWithDict.__init__L  s	    $r   c                 `    | j                   j                          t        j                          y)Nr   )rl  cleargccollectr   s    r   	__index__zHFastCallTests.test_fastcall_clearing_dict.<locals>.IntWithDict.__index__N  s    !!#

r   N)r   r   r   	__slots__ry  r~  r   r   r   IntWithDictrw  J  s    !
I%r   r  )optimizepassry   exec)compilerl  )r   r  rY   s      r   test_fastcall_clearing_dictz)FastCallTests.test_fastcall_clearing_dictG  s3    	 	 / 	FA22r   )"r   r   r   r4  rJ  rN  rP  rW  rY  PYTHON_INSTANCErR  rT  rg  rn  r   r8  	_instancer>  rE  r   r   extendr   r   ra  r'  r0  r  r   rc  r(  ro  rt  r  r   r   r   r[  r[    s0    
!Q  
r7# 
	!	!2}5		"	"B7 
		!Q0		%	%r73		%	%r=9		&	&N;#M6 
{QF+	a+aV4 
		{QF;			a%;aVDL '	&&(I	I	I			i112					 3 34			t$ "] 	vv'>?&&>@(?@]B$78''>@'']B68__b-0ZZ=#"67
 	 	&&c
]FS#J$GI&&S#JS#J ?A&&]FMBD''c
]FS#J$GI''S#JS#J ?A'']FMBD
 	+"H+84&4:3r   r[  i   i   c                     | S zsome docr   r   s    r   testfunctionr  ]      Kr   c                    | S r  r   )r   r"   s     r   testfunction_kwr  b  r  r   r   c                   r    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zed
        Zed        Zed        Zy)
TestPEP590c                    dd l } |j                  d      t              }| j                  t	        t
              j                  t        z         | j                  t	        t        j                        j                  t        z         | j                  t	        t        j                        j                  t        z         | j                  t	        t              j                  t        z         | j                  t	        |      j                  t        z         | j                  t        j                  j                  t        z         | j                  t        j                  j                  t        z         | j                  t        j                  j                  t        z          G d dt        j                        }| j                  |j                  t        z         y )Nr   r   c                       e Zd Zy)DTestPEP590.test_method_descriptor_flag.<locals>.MethodDescriptorHeapNr   r   r   r   r   r   MethodDescriptorHeapr  {      r   r  )	functools	lru_cacher  assertFalsetyperepr	__flags__Py_TPFLAGS_METHOD_DESCRIPTOR
assertTruer'   append__add__r   MethodDescriptorBaseMethodDescriptorDerivedMethodDescriptorNopGet)r   r  cachedr  s       r   test_method_descriptor_flagz&TestPEP590.test_method_descriptor_flagl  s>   '$$Q'5d--0LLMT[[)336RRST\\*447SST\*447SSTV..1MMN	66@@C__`	99CCFbbc99CCFbbc	9#A#A 	-77:VVWr   c                    | j                  t        j                  j                  t        z         | j                  t        j
                  j                  t        z         | j                  t        j                  j                  t        z         | j                  t        j                  j                  t        z          G d dt        j                        }| j                  |j                  t        z         t        |_
        | j                  |j                  t        z          G d dt        j                        }| j                  |j                  t        z         y )Nc                       e Zd Zy)=TestPEP590.test_vectorcall_flag.<locals>.MethodDescriptorHeapNr  r   r   r   r  r    r  r   r  c                       e Zd Zd Zy)r  c                      y r!   r   r   s    r   __call__zFTestPEP590.test_vectorcall_flag.<locals>.MethodDescriptorHeap.__call__  s    r   Nr   r   r   r  r   r   r   r  z=TestPEP590.test_vectorcall_flag.<locals>.MethodDescriptorHeap  s    r   )r  r   r  r  Py_TPFLAGS_HAVE_VECTORCALLr  r  r  MethodDescriptor2r   r  )r   r  s     r   test_vectorcall_flagzTestPEP590.test_vectorcall_flag  s    	66@@C]]^	99CCF``a99CCF``a	33==@ZZ[	9#A#A 	,669SST(-%-77:TTU	9#A#A 	 	-77:TTUr   c                 ~    t        t        d            }t        j                         }| j	                   || |       y )Nr   )r`  r4   r   r  assertIs)r   rf  r2   s      r   test_vectorcall_overridez#TestPEP590.test_vectorcall_override  s1     U1X,,.ah%r   c                     t        j                         } |       }| j                   |       d       |j                  |       | j                   |       d       d |_        | j                   |       d       y)z*Setting __call__ should disable vectorcalltp_call
vectorcallc                      yNcustomr   r   s    r   r   zFTestPEP590.test_vectorcall_override_on_mutable_class.<locals>.<lambda>  r   r   r  N)r   make_vectorcall_classr+   set_vectorcallr  )r   TestTypeinstances      r   )test_vectorcall_override_on_mutable_classz4TestPEP590.test_vectorcall_override_on_mutable_class  sc    224:Y/)\21X.r   c                 D   t        j                         } G d d|      } |       }t        j                  |      }t        j                  |      }| j                  t        ||             | j                  t        ||             | j	                   |       d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       |j                  |       | j	                   |       d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       d |_        | j	                   |       d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       | j	                  t        j
                  |      d       y	)
z:Setting __call__ on a superclass should disable vectorcallc                       e Zd Zy)FTestPEP590.test_vectorcall_override_with_subclass.<locals>.DerivedTypeNr  r   r   r   DerivedTyper    r  r   r  r  Tr  c                      yr  r   r   s    r   r   zCTestPEP590.test_vectorcall_override_with_subclass.<locals>.<lambda>  r   r   r  FN)r   r  r  
issubclassr+   has_vectorcall_flagr  r  )r   	SuperTyper  r  UnaffectedType1UnaffectedType2s         r   &test_vectorcall_override_with_subclassz1TestPEP590.test_vectorcall_override_with_subclass  s   335		) 	 = $99+F#99)D 	
?K@A
?I>? 	Y/66yA4H66{CTJ66GN66GN 		*\266yA4H66{CTJ66GN66GN 3	X.66yA5I66{CUK66GN66GNr   c                    t         t        d      fi dft        j                  g dfi d fg j                  di d ft        dgfddidft
        di dft        ddd idft        j                         di d	ft        j                         di d	ft        j                         di d
fg	}ddlmm} ddlm} ddlm} fd}|D ]_  \  }}}}	| j#                  t%        |            5  |s| j'                  |	 |||             | j'                  |	 ||||             d d d        a  G d dt        j                        }
 G d dt        j                        } G d d      } G d d|t        j                        }|t(        j*                  i fdd	id fi j*                  i fdd	id f |
       di d	f |       di df |       di d	fgz  }|D ]  \  }}}}	| j#                  t%        |            5  |dd  } |||d         } ||      }|sY| j'                  |	 ||        | j'                  |	 ||d              | j'                  |	 ||        | j'                  |	 ||        | j'                  |	 ||i |       | j'                  |	 ||||             | j'                  |	 ||i |       | j'                  |	 ||i |       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Nr   r   )r   $   start   )r   r"   TF)rq  pyvectorcall_call)
MethodType)partialc                 X    g ||j                         }t        |      } | ||      S r!   )rr  r`  )r~   rf  rl  rs  rq  s       r   r  z.TestPEP590.test_vectorcall.<locals>.vectorcall  s0    *D*6==?*DFmG&tT7;;r   c                       e Zd Zy)8TestPEP590.test_vectorcall.<locals>.MethodDescriptorHeapNr  r   r   r   r  r    r  r   r  c                       e Zd Zd Zy)>TestPEP590.test_vectorcall.<locals>.MethodDescriptorOverriddenc                      y)Nnewr   )r   ns     r   r  zGTestPEP590.test_vectorcall.<locals>.MethodDescriptorOverridden.__call__  s    r   Nr  r   r   r   MethodDescriptorOverriddenr    s    r   r  c                        e Zd Z fdZ xZS )-TestPEP590.test_vectorcall.<locals>.SuperBasec                     t        |   | S r!   superr  r   rf  	__class__s     r   r  z6TestPEP590.test_vectorcall.<locals>.SuperBase.__call__       w'..r   r   r   r   r  __classcell__r  s   @r   	SuperBaser        / /r   r  c                        e Zd Z fdZ xZS )9TestPEP590.test_vectorcall.<locals>.MethodDescriptorSuperc                     t        |   | S r!   r  r  s     r   r  zBTestPEP590.test_vectorcall.<locals>.MethodDescriptorSuper.__call__  r  r   r  r  s   @r   MethodDescriptorSuperr    r  r   r  r   r  r   )lenr4   r'   r  sumr  r  r   r  r  r  rq  r  r   r  r  r  rh  r   r+   r*   update)r   callsr  r  r  r  r~   rf  rl  r-   r  r  r  r  args1methwrappedrq  s                    @r   rt  zTestPEP590.test_vectorcall  s    b	|R,++AwD1))T2t,wR0r2.!54+r:002D"dC335tRF--/r5AC 	E$%	<
 /4 	R*T4c$i( R$$X/@t/LM  +<T4+PQR R	R	9#A#A 		)G)G 		/ 	/	/Iy/M/M 	/ 	[[2%%t4YYd|T2!#T2t4')4U;"$dB5
 	
 /4 	E*T4c$i( EQR!$Q0!$-$$XtT{;$$X/B4t/TU$$XtU|<$$Xw~>  4+@+@A  :dD&+IJ  4+A&+AB  7D+CF+CDE E	E?R R@E Es   6K$CKK	K	c                     ddl m} d }| j                  }d} |d ||              ||       t        dt        z        D ]  } |d ||              y )Nr   function_setvectorcallc                     | dz   S r   r   )nums    r   r2   z(TestPEP590.test_setvectorcall.<locals>.f   s
    37Nr   
      
overridden)r   r  r+   r4   ADAPTIVE_WARMUP_DELAY)r   r  r2   assert_equalr  r6   s         r   test_setvectorcallzTestPEP590.test_setvectorcall  sV    4"''R3 q!r112 	/Aqv.	/r   c                     ddl m}  G d d      }| j                  } |       } |d|j                          ||j                         t        t              D ]  } |d|j                          y )Nr   r  c                       e Zd Zd Zy)FTestPEP590.test_setvectorcall_load_attr_specialization_skip.<locals>.Xc                     |S r!   r   r   attrs     r   __getattribute__zWTestPEP590.test_setvectorcall_load_attr_specialization_skip.<locals>.X.__getattribute__-      r   Nr   r   r   r  r   r   r   Xr  ,      r   r  r   r  )r   r  r+   r   r  r4   r  )r   r  r  r  rY   r6   s         r   0test_setvectorcall_load_attr_specialization_skipz;TestPEP590.test_setvectorcall_load_attr_specialization_skip)  sd    4	 	 ''CS!##q112 ,- 	,Aqss+	,r   c                     ddl m}  G d d      }d }| j                  } |       }t        t              D ]  } |d ||               ||j
                         t        t              D ]  } |d ||              y )Nr   r  c                       e Zd Zd Zy)GTestPEP590.test_setvectorcall_load_attr_specialization_deopt.<locals>.Xc                     |S r!   r   r   s     r   r  zXTestPEP590.test_setvectorcall_load_attr_specialization_deopt.<locals>.X.__getattribute__=  r  r   Nr  r   r   r   r  r
  <  r  r   r  c                     | j                   S r!   )r   rX   s    r   get_azKTestPEP590.test_setvectorcall_load_attr_specialization_deopt.<locals>.get_a@  s    33Jr   r   r  )r   r  r+   r4   r  r  )r   r  r  r  r  rY   r6   s          r   1test_setvectorcall_load_attr_specialization_deoptz<TestPEP590.test_setvectorcall_load_attr_specialization_deopt9  s~    4	 		 ''C,- 	(AeAh'	(q112 ,- 	1AuQx0	1r   c                 l    ddl m} t        j                         }| j                   ||dd      d       y )Nr   )rq  r   zvectorcall called)r   rq  LimitedVectorCallClassr+   )r   rq  r   s      r    test_vectorcall_limited_incomingz+TestPEP590.test_vectorcall_limited_incomingN  s.    1..0,S"b9;NOr   c                     ddl m} g g fd}| j                   ||      d       | j                  dg       | j                  ddig       y )Nr   )call_vectorcallc                  J    j                  |        j                  |       yNsuccessr  )rf  rl  args_capturedkwargs_captureds     r   r2   z6TestPEP590.test_vectorcall_limited_outgoing.<locals>.f[  s"      &""6*r   r  r   bazbar)r   r  r+   )r   r  r2   r  r  s      @@r    test_vectorcall_limited_outgoingz+TestPEP590.test_vectorcall_limited_outgoingT  sU    -	
 	+Y7
3E5>*:;r   c                     ddl m} g g  G fdd      }| j                   | |             d       | j                  dg       | j                  ddig       y )	Nr   )call_vectorcall_methodc                       e Zd Z fdZy)HTestPEP590.test_vectorcall_limited_outgoing_method.<locals>.TestInstancec                 J    j                  |       j                  |       yr  r  )r   rf  rl  r  r  s      r   r2   zJTestPEP590.test_vectorcall_limited_outgoing_method.<locals>.TestInstance.fl  s"    $$T*&&v. r   N)r   r   r   r2   )r  r  s   r   TestInstancer!  k  s    !r   r#  r  r  r  r  )r   r  r+   )r   r  r#  r  r  s      @@r   'test_vectorcall_limited_outgoing_methodz2TestPEP590.test_vectorcall_limited_outgoing_methodd  s]    4	! 	! 	/?K
3E5>*:;r   N)r   r   r   r  r  r  r  r  rt  r  r  r  r   r  r  r$  r   r   r   r  r  j  st    X&V*&/'OTJEX	/, 1* P P
 < < < <r   r  c                   2    e Zd Zd Zed        Zed        Zy)Ac                      y r!   r   )r   rY   r]   s      r   method_two_argszA.method_two_argsv  s    r   c                       y r!   r   r   r   r   static_no_argszA.static_no_argsy      r   c                     y r!   r   args    r   positional_onlyzA.positional_only}  r+  r   N)r   r   r   r(  r   r*  r/  r   r   r   r&  r&  u  s/        r   r&  c                   N    e Zd Zej                  d        Zd Zd Zd Zd Z	d Z
y)!TestErrorMessagesUseQualifiedNamec              #      K   | j                  t              5 }d  d d d        | j                  t        j                        |       y # 1 sw Y   /xY wwr!   )assertRaisesr5   r+   r   	exception)r   messagecms      r   check_raises_type_errorz9TestErrorMessagesUseQualifiedName.check_raises_type_error  sF     y) 	R	R\\*G4	 	s   AA.AAAc                     d}| j                  |      5  t               j                  d       d d d        y # 1 sw Y   y xY w)Nz?A.method_two_args() missing 1 required positional argument: 'y'rY   r7  r&  r(  r>   s     r   test_missing_argumentsz8TestErrorMessagesUseQualifiedName.test_missing_arguments  s:    O))#. 	%C$	% 	% 	%s	   7A c                 ~    d}| j                  |      5  t        j                  d       d d d        y # 1 sw Y   y xY w)Nz?A.static_no_args() takes 0 positional arguments but 1 was givenzoops it's an arg)r7  r&  r*  r>   s     r   test_too_many_positionalz:TestErrorMessagesUseQualifiedName.test_too_many_positional  s9    O))#. 	1/0	1 	1 	1s   3<c                     d}| j                  |      5  t        j                  d       d d d        y # 1 sw Y   y xY w)NzYA.positional_only() got some positional-only arguments passed as keyword arguments: 'arg'rY   r-  )r7  r&  r/  r>   s     r   &test_positional_only_passed_as_keywordzHTestErrorMessagesUseQualifiedName.test_positional_only_passed_as_keyword  s;    i))#. 	'#&	' 	' 	's   4=c                     d}| j                  |      5  t               j                  d       d d d        y # 1 sw Y   y xY w)Nz<A.method_two_args() got an unexpected keyword argument 'bad'rY   )badr9  r>   s     r   test_unexpected_keywordz9TestErrorMessagesUseQualifiedName.test_unexpected_keyword  s=    L))#. 	)CC(	) 	) 	)s	   8Ac                     d}| j                  |      5  t               j                  ddd       d d d        y # 1 sw Y   y xY w)Nz8A.method_two_args() got multiple values for argument 'x'rY   r]   oopsrX   r9  r>   s     r   test_multiple_valuesz6TestErrorMessagesUseQualifiedName.test_multiple_values  sA    H))#. 	4CSF3	4 	4 	4s	   :AN)r   r   r   
contextlibcontextmanagerr7  r:  r<  r>  rA  rD  r   r   r   r1  r1    s5     5 5
%
1
'
)
4r   r1  c                   P    e Zd Ze ej
                  exr ed      d               Zy)TestRecursionzrequires deep stackc                 D   fdfdfdfdt        j                         }t        j                  d       	  d       | j                  t              5   d       d d d         d       | j                  t              5   d       d d d         d	       | j                  t              5   d       d d d        t        j                  |       y # 1 sw Y   {xY w# 1 sw Y   YxY w# 1 sw Y   7xY w# t        j                  |       w xY w)
Nc                 "    | r | dz
         y y r   r   )r  recurses    r   rK  z.TestRecursion.test_super_deep.<locals>.recurse  s    ! r   c                 :    | r | dz
  |       y  |dz
         y r   r   )r  mc_py_recurse
py_recurses     r   rO  z1TestRecursion.test_super_deep.<locals>.py_recurse  s     1Q3"QqS!r   c                 @    | rt        j                  | dz
  f       y y r   r   ri  )r  	c_recurses    r   rR  z0TestRecursion.test_super_deep.<locals>.c_recurse  s!    ++I!v> r   c                 <    | rt        j                  d| f       y y )Nr3   rQ  )rM  rO  s    r   rN  z3TestRecursion.test_super_deep.<locals>.c_py_recurse  s    ++Jq	B r   i i_ i d   Z   )sysgetrecursionlimitsetrecursionlimitr3  RecursionError)r   depthrN  rR  rO  rK  s     @@@@r   test_super_deepzTestRecursion.test_super_deep  s    		"	?	C %%'g&	)FO"">2 ! !cN"">2 "&!""">2 &W%& !!%(! !" "& & !!%(sT   D !	C$*%D 	C0%D =	C<D $C-)D 0C95D <DD DN)	r   r   r   r   unittestskipIfr   r   r[  r   r   r   rH  rH    s2     X__W)+@A!) B !)r   rH  c                       e Zd Zd Zy)TestFunctionWithManyArgsc           	      <   dD ]  }| j                  |      5  dj                  t        |      D cg c]  }d| 	 c}      }d| d|dz   }i }t        |i |       | j	                   |d   t        |       |dz         d d d         y c c}w # 1 sw Y   xY w)	N)r  i  r3   )Nr   r   zdef f(z) : return ar   r2   )rh  joinr4   r  r+   )r   ra  irf  srcls         r   test_function_with_many_argsz5TestFunctionWithManyArgs.test_function_with_many_args  s      	:A" :xx%( ;Q1QC ;<tfLA7S"a   3q!2AqD9: :	: ;: :s   BBABBB	N)r   r   r   rf  r   r   r   r_  r_    s    :r   r_  __main__)-r\  test.supportr   r   r   r   r   r   r   ro   r$   r   r|  rE  rV  r   r   r	   TestCaser   r9   r   r6  r;  r@  rC  rJ  rN  rP  r  r   ra  r[  r  r  r  r  r  r  r&  r1  rH  r_  r   mainr   r   r   <module>rk     s    ] ]    	  
 &S &H%% 8 w4("3"3 w4 w4tH
X.. H
VA%; A<"8 <1*@ 1"#9 "   -b3H%% b3J % & 

  I<"" I<V
 
 4(9(9 4 4B %)H%% %) %)N:x00 : zHMMO c  Is   E. .E98E9