
    <e3                     p   d dl Z d dlZd dlZd dlmZ  G d de j                  Z G d de j                  Z G d de          Z	 G d	 d
e          Z
 e	d          Z e	ef          Z G d d          Z G d de          Z G d de j                  Zd Zedk    r e j                     dS dS )    N)supportc                   ,    e Zd Zd Zd Zd Zd Zd ZdS )TestIsInstanceExceptionsc                      G d dt                     } G d dt                     }|                     dt           |             |                                 d S )Nc                   *    e Zd Zd Z ee          ZdS );TestIsInstanceExceptions.test_class_has_no_bases.<locals>.Ic                     d S N selfs    +/usr/lib/python3.11/test/test_isinstance.pygetclasszDTestIsInstanceExceptions.test_class_has_no_bases.<locals>.I.getclass   s    t    N__name__
__module____qualname__r   property	__class__r   r   r   Ir      s.           !**IIIr   r   c                   *    e Zd Zd Z ee          ZdS );TestIsInstanceExceptions.test_class_has_no_bases.<locals>.Cc                     dS Nr   r   r   s    r   getbaseszDTestIsInstanceExceptions.test_class_has_no_bases.<locals>.C.getbases"       rr   Nr   r   r   r   r   	__bases__r   r   r   Cr   !   ,           **IIIr   r    F)objectassertEqual
isinstancer   r   r    s      r   test_class_has_no_basesz0TestIsInstanceExceptions.test_class_has_no_bases   s    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	
1133 4 455555r   c                      G d dt                      G fddt                     } G d dt                     }|                     t          t           |             |                       d S )Nc                   *    e Zd Zd Z ee          ZdS )PTestIsInstanceExceptions.test_bases_raises_other_than_attribute_error.<locals>.Ec                     t           r
   RuntimeErrorr   s    r   r   zYTestIsInstanceExceptions.test_bases_raises_other_than_attribute_error.<locals>.E.getbases,       ""r   Nr   r   r   r   Er)   +   ,        # # # **IIIr   r.   c                   0    e Zd Z fdZ ee          ZdS )PTestIsInstanceExceptions.test_bases_raises_other_than_attribute_error.<locals>.Ic                                  S r
   r   )r   r.   s    r   r   zYTestIsInstanceExceptions.test_bases_raises_other_than_attribute_error.<locals>.I.getclass1   s    qss
r   Nr   )r.   s   r   r   r1   0   s7             **IIIr   r   c                   *    e Zd Zd Z ee          ZdS )PTestIsInstanceExceptions.test_bases_raises_other_than_attribute_error.<locals>.Cc                     dS r   r   r   s    r   r   zYTestIsInstanceExceptions.test_bases_raises_other_than_attribute_error.<locals>.C.getbases6   r   r   Nr   r   r   r   r    r4   5   r!   r   r    r"   assertRaisesr,   r$   )r   r   r    r.   s      @r   ,test_bases_raises_other_than_attribute_errorzETestIsInstanceExceptions.test_bases_raises_other_than_attribute_error*   s    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	,
AACC=====r   c                      G d d          } G d dt                     }|                     t          t           |             |                       d S )Nc                       e Zd ZdS )FTestIsInstanceExceptions.test_dont_mask_non_attribute_error.<locals>.INr   r   r   r   r   r   r   r;   ?             r   r   c                   *    e Zd Zd Z ee          ZdS )FTestIsInstanceExceptions.test_dont_mask_non_attribute_error.<locals>.Cc                     t           r
   r+   r   s    r   r   zOTestIsInstanceExceptions.test_dont_mask_non_attribute_error.<locals>.C.getbasesB   r-   r   Nr   r   r   r   r    r?   A   r/   r   r    r6   r%   s      r   "test_dont_mask_non_attribute_errorz;TestIsInstanceExceptions.test_dont_mask_non_attribute_error>   sk    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	,
AACC=====r   c                      G d d          } G d dt                     }|                     t          t           |             |                       d S )Nc                       e Zd ZdS )=TestIsInstanceExceptions.test_mask_attribute_error.<locals>.INr<   r   r   r   r   rD   K   r=   r   r   c                   *    e Zd Zd Z ee          ZdS )=TestIsInstanceExceptions.test_mask_attribute_error.<locals>.Cc                     t           r
   AttributeErrorr   s    r   r   zFTestIsInstanceExceptions.test_mask_attribute_error.<locals>.C.getbasesN       $$r   Nr   r   r   r   r    rF   M   ,        % % % **IIIr   r    )r"   r7   	TypeErrorr$   r%   s      r   test_mask_attribute_errorz2TestIsInstanceExceptions.test_mask_attribute_errorJ   sk    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	)Zaacc:::::r   c                      G d dt                     } |            }|                     t          t          |t                      G d d          }|                     t          t          ||           d S )Nc                   *    e Zd Zd Z ee          ZdS )QTestIsInstanceExceptions.test_isinstance_dont_mask_non_attribute_error.<locals>.Cc                     t           r
   r+   r   s    r   r   zZTestIsInstanceExceptions.test_isinstance_dont_mask_non_attribute_error.<locals>.C.getclassX   r-   r   Nr   r   r   r   r    rP   W   r/   r   r    c                       e Zd ZdS )QTestIsInstanceExceptions.test_isinstance_dont_mask_non_attribute_error.<locals>.DNr<   r   r   r   DrS   `   r=   r   rT   )r"   r7   r,   r$   bool)r   r    crT   s       r   -test_isinstance_dont_mask_non_attribute_errorzFTestIsInstanceExceptions.test_isinstance_dont_mask_non_attribute_errorV   s    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 ACC,
At<<< 	,
Aq99999r   N)r   r   r   r&   r8   rA   rM   rW   r   r   r   r   r      s_        6 6 6 > > >(> > >; ; ;: : : : :r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )TestIsSubclassExceptionsc                      G d dt                     } G d d|          }|                     t          t           |             |                       d S )Nc                   *    e Zd Zd Z ee          ZdS )FTestIsSubclassExceptions.test_dont_mask_non_attribute_error.<locals>.Cc                     t           r
   r+   r   s    r   r   zOTestIsSubclassExceptions.test_dont_mask_non_attribute_error.<locals>.C.getbasesj   r-   r   Nr   r   r   r   r    r\   i   r/   r   r    c                       e Zd ZdS )FTestIsSubclassExceptions.test_dont_mask_non_attribute_error.<locals>.SNr<   r   r   r   Sr_   n   r=   r   r`   r"   r7   r,   
issubclassr   r    r`   s      r   rA   z;TestIsSubclassExceptions.test_dont_mask_non_attribute_errorh   st    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	,
AACC=====r   c                      G d dt                     } G d d|          }|                     t          t           |             |                       d S )Nc                   *    e Zd Zd Z ee          ZdS )=TestIsSubclassExceptions.test_mask_attribute_error.<locals>.Cc                     t           r
   rH   r   s    r   r   zFTestIsSubclassExceptions.test_mask_attribute_error.<locals>.C.getbasest   rJ   r   Nr   r   r   r   r    rf   s   rK   r   r    c                       e Zd ZdS )=TestIsSubclassExceptions.test_mask_attribute_error.<locals>.SNr<   r   r   r   r`   ri   x   r=   r   r`   r"   r7   rL   rb   rc   s      r   rM   z2TestIsSubclassExceptions.test_mask_attribute_errorr   st    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	)Zaacc:::::r   c                      G d d          } G d dt                     }|                     t          t          | |                       d S )Nc                       e Zd ZdS )QTestIsSubclassExceptions.test_dont_mask_non_attribute_error_in_cls_arg.<locals>.BNr<   r   r   r   Brm      r=   r   rn   c                   *    e Zd Zd Z ee          ZdS )QTestIsSubclassExceptions.test_dont_mask_non_attribute_error_in_cls_arg.<locals>.Cc                     t           r
   r+   r   s    r   r   zZTestIsSubclassExceptions.test_dont_mask_non_attribute_error_in_cls_arg.<locals>.C.getbases   r-   r   Nr   r   r   r   r    rp      r/   r   r    ra   r   rn   r    s      r   -test_dont_mask_non_attribute_error_in_cls_argzFTestIsSubclassExceptions.test_dont_mask_non_attribute_error_in_cls_arg   se    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	,
Aqqss;;;;;r   c                      G d d          } G d dt                     }|                     t          t          | |                       d S )Nc                       e Zd ZdS )HTestIsSubclassExceptions.test_mask_attribute_error_in_cls_arg.<locals>.BNr<   r   r   r   rn   rv      r=   r   rn   c                   *    e Zd Zd Z ee          ZdS )HTestIsSubclassExceptions.test_mask_attribute_error_in_cls_arg.<locals>.Cc                     t           r
   rH   r   s    r   r   zQTestIsSubclassExceptions.test_mask_attribute_error_in_cls_arg.<locals>.C.getbases   rJ   r   Nr   r   r   r   r    rx      rK   r   r    rj   rr   s      r   $test_mask_attribute_error_in_cls_argz=TestIsSubclassExceptions.test_mask_attribute_error_in_cls_arg   se    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 	)ZAACC88888r   N)r   r   r   rA   rM   rs   rz   r   r   r   rY   rY   g   sP        > > >; ; ;< < <9 9 9 9 9r   rY   c                   6    e Zd Zd Zd Z ee          Zd ZdS )AbstractClassc                     || _         d S r
   bases)r   r   s     r   __init__zAbstractClass.__init__       


r   c                     | j         S r
   r~   r   s    r   r   zAbstractClass.getbases   
    zr   c                      t          |           S r
   )AbstractInstancer   s    r   __call__zAbstractClass.__call__   s    %%%r   N)r   r   r   r   r   r   r   r   r   r   r   r|   r|      sP            ""I& & & & &r   r|   c                   0    e Zd Zd Zd Z ee          ZdS )r   c                     || _         d S r
   klass)r   r   s     r   r   zAbstractInstance.__init__   r   r   c                     | j         S r
   r   r   s    r   r   zAbstractInstance.getclass   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r      s;            ""IIIr   r   r   r~   c                       e Zd ZdS )SuperNr<   r   r   r   r   r              Dr   r   c                       e Zd ZdS )ChildNr<   r   r   r   r   r      r   r   r   c                   b    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S )TestIsInstanceIsSubclassc                    |                      dt          t                      t                               |                      dt          t                      t                               |                      dt          t                      t                               |                      dt          t                      t
                               |                      dt          t                      t                               |                      dt          t                      t                               d S NTF)r#   r$   r   r   AbstractSuperAbstractChildr   s    r   test_isinstance_normalz/TestIsInstanceIsSubclass.test_isinstance_normal   s    z%''599:::
577E : :;;;
577M B BCCC
577M B BCCCz%''599:::
577M B BCCCCCr   c                 V   |                      dt          t                      t                               |                      dt          t                      t                               |                      dt          t                      t                               |                      dt          t                      t
                               |                      dt          t                      t                               |                      dt          t                      t                               |                      dt          t                      t                               |                      dt          t                      t
                               d S r   )r#   r$   r   r   r   r   r   s    r   test_isinstance_abstractz1TestIsInstanceIsSubclass.test_isinstance_abstract   s(   z-//=IIJJJ
=??M J JKKK
=??E B BCCC
=??E B BCCCz-//=IIJJJz-//=IIJJJ
=??E B BCCC
=??E B BCCCCCr   c                    |                      t          t                      t          t          z                       |                     t          d t
          t          z                       |                      t          dt
          t          z                       |                      t          dt
          t          z                       |                      t          g t          j        t          j        z                       |                      t          dt          j        t          z                       |                     t          dt          j        t          j        z                       |                      t          d t          d z                       |                     t          dt          t
          z                       | 	                    t                    5  t          dt          t                              d d d            n# 1 swxY w Y   | 	                    t                    5  t          dt          t                   t          z             d d d            n# 1 swxY w Y   | 	                    t                    5  t          dt          t
          z  t          t                   z  t          z             d d d            d S # 1 swxY w Y   d S )N       gQ	@)
assertTruer$   r   intassertFalsestrtypingListTupler7   rL   listfloatr   s    r   test_isinstance_with_or_unionz6TestIsInstanceIsSubclass.test_isinstance_with_or_union   s   
577ECK88999D#)44555
1cCi00111
2sSy11222
2v{V\'ABBCCC
1fkC&788999Av{V\'ABBCCC
4t44555D#)44555y)) 	% 	%q$s)$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%y)) 	+ 	+q$s)c/***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+y)) 	9 	9q%#+S	1C7888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s6   +!HHH=)I22I69I69KK!$K!c                 4   |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                     t          t          j        t          j        t          j        z                       | 	                    t          t          t          j        t          j        z                       d S r   )r#   rb   r   r   r   r   r   r   r   r   r   r   s    r   test_subclass_normalz-TestIsInstanceIsSubclass.test_subclass_normal   s   z%77888
5- @ @AAA
5% 8 8999z%77888z%77888
5- @ @AAA
6;FL0HIIJJJCV\)ABBCCCCCr   c                    |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t                               |                      dt          t          t
                               |                      dt          t          t                               d S r   )r#   rb   r   r   r   r   r   s    r   test_subclass_abstractz/TestIsInstanceIsSubclass.test_subclass_abstract   s    z-GGHHH
=- H HIII
=% @ @AAAz-GGHHHz-GGHHH
=% @ @AAA
=% @ @AAAAAr   c           	      8   |                      dt          t          t          f                     |                      dt          t          t          f                     |                      dt          t          t          f                     |                      dt          t          t          t          f                     |                      dt          t          d                     |                      dt          t          t          t          ff                     |                      dt          t          t          t
          t          ff                     |                      dt          t          t          t          t          ff                     d S )NTFr   )r#   rb   r   r   r   r   r   r   s    r   test_subclass_tuplez,TestIsInstanceIsSubclass.test_subclass_tuple   s+   z%%::;;;z%%::;;;
55( ; ;<<<z%%@@AAA
5" 5 5666z%%%1BCCDDDz#eS\/BCCDDDz#eS\/BCCDDDDDr   c                     t          j                    5  |                     t          t          t
          t          t                     d d d            d S # 1 swxY w Y   d S r
   )r   infinite_recursionr7   RecursionError	blowstackrb   r   r   s    r   test_subclass_recursion_limitz6TestIsInstanceIsSubclass.test_subclass_recursion_limit	  s     ')) 	O 	OniS#NNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	Os   3AAAc                     t          j                    5  |                     t          t          t
          dt                     d d d            d S # 1 swxY w Y   d S )Nr   )r   r   r7   r   r   r$   r   r   s    r   test_isinstance_recursion_limitz8TestIsInstanceIsSubclass.test_isinstance_recursion_limit  s     ')) 	N 	NniRMMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   .AAAc                 ,   |                      t          t          t          t          z  t          z                       |                      t          t          t          t
          z  t          z                       |                     t          t          t          t          z                       |                     t          t          t          t          z                       | 	                    t                    5  t          dt
          t          z             d d d            n# 1 swxY w Y   | 	                    t                    5  t          t          t          t                   t
          z             d d d            d S # 1 swxY w Y   d S )Nr   )r   rb   r   r   r   r   r   dictr"   r7   rL   r   r   r   s    r   test_subclass_with_unionz1TestIsInstanceIsSubclass.test_subclass_with_union  s   
3ec(9::;;;
3ec(9::;;;D%)44555FE#I66777y)) 	) 	)q%%-(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)y)) 	/ 	/sDI-...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s$   ?D))D-0D-.F		FFc                      G d d           G fdd          }|                      dt           |            t                               d S )Nc                   $    e Zd Zed             ZdS )ETestIsInstanceIsSubclass.test_issubclass_refcount_handling.<locals>.Ac                     t           fS r
   )r   r   s    r   r   zOTestIsInstanceIsSubclass.test_issubclass_refcount_handling.<locals>.A.__bases__#  s	    wr   Nr   r   r   r   r   r   r   r   Ar   "  s-          X  r   r   c                   0    e Zd Zd Ze fd            ZdS )ETestIsInstanceIsSubclass.test_issubclass_refcount_handling.<locals>.Bc                     d| _         d S )N   )xr   s    r   r   zNTestIsInstanceIsSubclass.test_issubclass_refcount_handling.<locals>.B.__init__(  s     r   c                                  fS r
   r   )r   r   s    r   r   zOTestIsInstanceIsSubclass.test_issubclass_refcount_handling.<locals>.B.__bases__-  s    wr   N)r   r   r   r   r   r   )r   s   r   rn   r   '  sI          
     X  r   rn   T)r#   rb   r   )r   rn   r   s     @r   !test_issubclass_refcount_handlingz:TestIsInstanceIsSubclass.test_issubclass_refcount_handling  s    	 	 	 	 	 	 	 	
	 	 	 	 	 	 	 	 	 	 	z!!##s3344444r   c                     G d d          }t          j                    5  |                     t          t           |            t
                     |                     t          t          t
           |                       |                     t          t          d |                       d d d            d S # 1 swxY w Y   d S )Nc                   $    e Zd Zed             ZdS )DTestIsInstanceIsSubclass.test_infinite_recursion_in_bases.<locals>.Xc                     | j         S r
   )r   r   s    r   r   zNTestIsInstanceIsSubclass.test_infinite_recursion_in_bases.<locals>.X.__bases__5  s
    ~%r   Nr   r   r   r   Xr   4  s-        & & X& & &r   r   r   )r   r   r7   r   rb   r   r$   r   r   s     r    test_infinite_recursion_in_basesz9TestIsInstanceIsSubclass.test_infinite_recursion_in_bases3  s   	& 	& 	& 	& 	& 	& 	& 	& ')) 	B 	Bnj!!##sCCCnj#qqssCCCnj!QQSSAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bs   B	B77B;>B;c                 "    G d dt                     }t          j                    5  |                     t                    5  t           |            t                     ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )Regression test for bpo-30570.c                       e Zd Zd ZdS )QTestIsInstanceIsSubclass.test_infinite_recursion_via_bases_tuple.<locals>.Failurec                 
    | d fS r
   r   )r   attrs     r   __getattr__z]TestIsInstanceIsSubclass.test_infinite_recursion_via_bases_tuple.<locals>.Failure.__getattr__@  s    d|#r   Nr   r   r   r   r   r   r   Failurer   ?  s#        $ $ $ $ $r   r   N)r"   r   r   r7   r   rb   r   )r   r   s     r   'test_infinite_recursion_via_bases_tuplez@TestIsInstanceIsSubclass.test_infinite_recursion_via_bases_tuple=  s    	$ 	$ 	$ 	$ 	$f 	$ 	$ 	$ ')) 	+ 	+"">22 + +7799c***+ + + + + + + + + + + + + + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s5   BA, B,A0	0B3A0	4BBBc                      G d d          }t          j                    5  |                     t          t           |            t
                     ddd           dS # 1 swxY w Y   dS )r   c                   $    e Zd Zed             ZdS )@TestIsInstanceIsSubclass.test_infinite_cycle_in_bases.<locals>.Xc                     | | | fS r
   r   r   s    r   r   zJTestIsInstanceIsSubclass.test_infinite_cycle_in_bases.<locals>.X.__bases__I  s    dD))r   Nr   r   r   r   r   r   H  s-        * * X* * *r   r   Nr   r   r7   r   rb   r   r   s     r   test_infinite_cycle_in_basesz5TestIsInstanceIsSubclass.test_infinite_cycle_in_basesF  s    	* 	* 	* 	* 	* 	* 	* 	* ')) 	D 	Dnj!!##sCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   0AA"%A"c                      G fdd          t          j                    5  |                     t          t                       t
                     ddd           dS # 1 swxY w Y   dS )r   c                       e Zd Z fdZdS )>TestIsInstanceIsSubclass.test_infinitely_many_bases.<locals>.Xc                     |                      |d            G d d          } G d d          }j        x|_        |_         |             |            fS )Nr   c                       e Zd ZdS )UTestIsInstanceIsSubclass.test_infinitely_many_bases.<locals>.X.__getattr__.<locals>.ANr<   r   r   r   r   r   T          Dr   r   c                       e Zd ZdS )UTestIsInstanceIsSubclass.test_infinitely_many_bases.<locals>.X.__getattr__.<locals>.BNr<   r   r   r   rn   r   V  r   r   rn   )r#   r   )r   r   r   rn   r   s       r   r   zJTestIsInstanceIsSubclass.test_infinitely_many_bases.<locals>.X.__getattr__R  s      {333              01=QQSSz!r   Nr   )r   s   r   r   r   Q  s.        " " " " " " "r   r   Nr   r   s    @r   test_infinitely_many_basesz3TestIsInstanceIsSubclass.test_infinitely_many_basesO  s    	" 	" 	" 	" 	" 	" 	" 	" 	" 	" ')) 	D 	Dnj!!##sCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   0A!!A%(A%N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s       D D D
D 
D 
D9 9 9&
D 
D 
D	B 	B 	B
E 
E 
EO O ON N N/ / /5 5 5(B B B+ + +D D DD D D D Dr   r   c                 v    |f}t          t          j                    dz             D ]}|f} | ||           d S )N   )rangesysgetrecursionlimit)fxnarg
compare_to	tuple_argcnts        r   r   r   ^  sV     IS*,,Q.//  L	C r   __main__)unittestr   r   testr   TestCaser   rY   r"   r|   r   r   r   r   r   r   r   r   mainr   r   r   <module>r      s  
  



       V: V: V: V: V:x0 V: V: V:x+9 +9 +9 +9 +9x0 +9 +9 +9^	& 	& 	& 	& 	&F 	& 	& 	&# # # # #v # # # B''']$4555	 	 	 	 	 	 	 		 	 	 	 	E 	 	 	fD fD fD fD fDx0 fD fD fDR   zHMOOOOO r   