
    7bh<F                         d Z ddlZddlZddlZdZdZd Z G d dej                        Ze	dk(  r ej                          yy)	z&
Test the API of the symtable module.
    Na  
import sys

glob = 42
some_var = 12
some_non_assigned_global_var: int
some_assigned_global_var = 11

class Mine:
    instance_var = 24
    def a_method(p1, p2):
        pass

def spam(a, b, *var, **kw):
    global bar
    global some_assigned_global_var
    some_assigned_global_var = 12
    bar = 47
    some_var = 10
    x = 23
    glob
    def internal():
        return x
    def other_internal():
        nonlocal some_var
        some_var = 3
        return some_var
    return internal

def foo():
    pass

def namespace_test(): pass
def namespace_test(): pass

type Alias = int
type GenericAlias[T] = list[T]

def generic_spam[T](a):
    pass

class GenericMine[T: int]:
    pass
aS  
# The following symbols are defined in ComplexClass
# without being introduced by a 'global' statement.
glob_unassigned_meth: Any
glob_unassigned_meth_pep_695: Any

glob_unassigned_async_meth: Any
glob_unassigned_async_meth_pep_695: Any

def glob_assigned_meth(): pass
def glob_assigned_meth_pep_695[T](): pass

async def glob_assigned_async_meth(): pass
async def glob_assigned_async_meth_pep_695[T](): pass

# The following symbols are defined in ComplexClass after
# being introduced by a 'global' statement (and therefore
# are not considered as local symbols of ComplexClass).
glob_unassigned_meth_ignore: Any
glob_unassigned_meth_pep_695_ignore: Any

glob_unassigned_async_meth_ignore: Any
glob_unassigned_async_meth_pep_695_ignore: Any

def glob_assigned_meth_ignore(): pass
def glob_assigned_meth_pep_695_ignore[T](): pass

async def glob_assigned_async_meth_ignore(): pass
async def glob_assigned_async_meth_pep_695_ignore[T](): pass

class ComplexClass:
    a_var = 1234
    a_genexpr = (x for x in [])
    a_lambda = lambda x: x

    type a_type_alias = int
    type a_type_alias_pep_695[T] = list[T]

    class a_class: pass
    class a_class_pep_695[T]: pass

    def a_method(self): pass
    def a_method_pep_695[T](self): pass

    async def an_async_method(self): pass
    async def an_async_method_pep_695[T](self): pass

    @classmethod
    def a_classmethod(cls): pass
    @classmethod
    def a_classmethod_pep_695[T](self): pass

    @classmethod
    async def an_async_classmethod(cls): pass
    @classmethod
    async def an_async_classmethod_pep_695[T](self): pass

    @staticmethod
    def a_staticmethod(): pass
    @staticmethod
    def a_staticmethod_pep_695[T](self): pass

    @staticmethod
    async def an_async_staticmethod(): pass
    @staticmethod
    async def an_async_staticmethod_pep_695[T](self): pass

    # These ones will be considered as methods because of the 'def' although
    # they are *not* valid methods at runtime since they are not decorated
    # with @staticmethod.
    def a_fakemethod(): pass
    def a_fakemethod_pep_695[T](): pass

    async def an_async_fakemethod(): pass
    async def an_async_fakemethod_pep_695[T](): pass

    # Check that those are still considered as methods
    # since they are not using the 'global' keyword.
    def glob_unassigned_meth(): pass
    def glob_unassigned_meth_pep_695[T](): pass

    async def glob_unassigned_async_meth(): pass
    async def glob_unassigned_async_meth_pep_695[T](): pass

    def glob_assigned_meth(): pass
    def glob_assigned_meth_pep_695[T](): pass

    async def glob_assigned_async_meth(): pass
    async def glob_assigned_async_meth_pep_695[T](): pass

    # The following are not picked as local symbols because they are not
    # visible by the class at runtime (this is equivalent to having the
    # definitions outside of the class).
    global glob_unassigned_meth_ignore
    def glob_unassigned_meth_ignore(): pass
    global glob_unassigned_meth_pep_695_ignore
    def glob_unassigned_meth_pep_695_ignore[T](): pass

    global glob_unassigned_async_meth_ignore
    async def glob_unassigned_async_meth_ignore(): pass
    global glob_unassigned_async_meth_pep_695_ignore
    async def glob_unassigned_async_meth_pep_695_ignore[T](): pass

    global glob_assigned_meth_ignore
    def glob_assigned_meth_ignore(): pass
    global glob_assigned_meth_pep_695_ignore
    def glob_assigned_meth_pep_695_ignore[T](): pass

    global glob_assigned_async_meth_ignore
    async def glob_assigned_async_meth_ignore(): pass
    global glob_assigned_async_meth_pep_695_ignore
    async def glob_assigned_async_meth_pep_695_ignore[T](): pass
c                 \    | j                         D ]  }|j                         |k(  s|c S  y N)get_childrenget_name)blocknamechs      </opt/python-3.12.12/usr/lib/python3.12/test/test_symtable.py
find_blockr      s(      ";;=D I #    c                      e Zd Z ej                  edd      Z eed      Z eed      Z eed      Z	 ee	d      Z
 ee	d      Z eed      Z eed	      Z eed
      Z eed
      Z eed      Z eed      Z eed      Z eed      Z ee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))*SymtableTest?execMinea_methodspaminternalother_internalfooAliasGenericAliasgeneric_spamGenericMineTc                    | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j
                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       y )Nmoduleclassfunctionz
type aliasztype parameterzTypeVar bound)assertEqualtopget_typer   r   r   r   r   r   r   GenericAlias_innerr   generic_spam_innerr   GenericMine_innerr   selfs    r
   	test_typezSymtableTest.test_type   s   **,h7++-w7//1:>++-z://1:>**,j9,,.=**3357GH0099;\J**3357GH0099;ZH))2246FG//88:GD*O<r   c                 L   | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j
                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j                         d       y )Nr   )assertGreaterr!   get_idr   r   r   r   r   r   r   r   r   r&   s    r
   test_idzSymtableTest.test_id   s&   488??,a0499++-q14==//115499++-q14==//115488??,a04::,,.24,,335q94,,335q94++224a8r   c                     | j                  | j                  j                                | j                  | j                  j                                y r   )assertFalser!   is_optimized
assertTruer   r&   s    r
   test_optimizedzSymtableTest.test_optimized   s6    ..01		..01r   c                 L   | j                  | j                  j                                | j                  | j                  j                                | j                  | j                  j                                | j                  | j                  j                                y r   )r.   r!   	is_nestedr   r   r0   r   r&   s    r
   test_nestedzSymtableTest.test_nested   sl    ++-.,,./,,.///12r   c                     | j                  | j                  j                                | j                  | j                  j                                | j	                  | j
                  j                                y r   )r0   r!   has_childrenr   r.   r   r&   s    r
   test_childrenzSymtableTest.test_children   sO    --/0		..01..01r   c                     | j                  | j                  j                         d       | j                  | j                  j                         d       y )Nr      )r    r!   
get_linenor   r&   s    r
   test_linenozSymtableTest.test_lineno   s<    ,,.2--/4r   c                 v   | j                   }| j                  t        |j                               g d       g d}| j                  t        |j	                               |       | j                  t        |j                               g d       | j                  | j                  j                         d       y )N)abkwvar)r=   r>   r   r?   r   some_varr@   x)barglobsome_assigned_global_var)rB   )r   r    sortedget_parameters
get_localsget_globalsr   	get_frees)r'   funcexpecteds      r
   test_function_infozSymtableTest.test_function_info   s    yy 3 3 568OPY 12H= 0 0 235`a002F;r   c                    | j                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                y )NrD   rC   rB   instance_varsome_non_assigned_global_varrE   )	r0   r   lookup	is_globalr.   is_declared_globalr   r   r!   r&   s    r
   test_globalszSymtableTest.test_globals   sJ   		((0::<=))&1DDFG		((/99;<		((/BBDE--c2<<>?)).9CCEF		((/99;<(FGQQST(BCMMOPr   c                 <   | j                  | j                  j                  d      j                                | j	                  | j
                  j                  d      j                                d}| j                  | j
                  j                         |       y )NrA   )rA   )r.   r   rQ   is_nonlocalr0   r   r    get_nonlocalsr'   rL   s     r
   test_nonlocalzSymtableTest.test_nonlocal	  sr    ))*5AACD++22:>JJLM ,,::<hGr   c                    | j                  | j                  j                  d      j                                | j	                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j
                  j                  d      j                                y )NrB   rC   rP   rE   )r0   r   rQ   is_localr.   r!   r&   s    r
   
test_localzSymtableTest.test_local  s    		((-6689))%099;<(FGPPRS(BCLLNOr   c                 t    | j                  | j                  j                  d      j                                y )NrB   )r0   r   rQ   is_freer&   s    r
   	test_freezSymtableTest.test_free  s&    ,,S199;<r   c                 T   | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                y )NrB   r   )r0   r   rQ   is_referencedr   r.   r&   s    r
   test_referencedzSymtableTest.test_referenced  sp    ,,S1??AB		((4BBDE))#.<<>?r   c                     dD ]:  }| j                  | j                  j                  |      j                                < | j	                  | j                  j                  d      j                                y )N)r=   r@   r?   rB   )r0   r   rQ   is_parameterr.   )r'   syms     r
   test_parameterszSymtableTest.test_parameters  sV    %COODII,,S1>>@A &))#.;;=>r   c                    | j                  t        | j                  j                               t        | j                  j	                                      | j                  t        | j                  j                  d       y )Nnot_here)r    lenr!   get_identifiersget_symbolsassertRaisesKeyErrorrQ   r&   s    r
   test_symbol_lookupzSymtableTest.test_symbol_lookup#  sU    TXX5578TXX1134	6 	(DHHOOZ@r   c                    | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j                  j                  d      j                         | j
                  u        | j                  j                  d      }| j                  t        |j                               d       | j                  t        |j                         | j                  j                  d      }| j                  t        |j                               d	       | j                  t        |j                         y )
Nr   r   r   r   namespace_testrB      rD   r   )r0   r!   rQ   is_namespacer   r   r.   get_namespacer    ri   get_namespacesrl   
ValueError)r'   ns_test	ns_test_2s      r
   test_namespaceszSymtableTest.test_namespaces)  s   /<<>?		((4AACD/<<>?		((4AACD(89FFHI))#.;;=>/==?499LM((//"23W3356:*g&;&;<HHOOF+	Y5578!<*i&=&=>r   c                 4   | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j                  j                  d      j                                | j                  | j
                  j                  d      j                                | j                  | j                  j                  d      j                                y )NrB   rC   r   r   )r0   r   rQ   is_assignedr!   r   r.   r   r&   s    r
   test_assignedzSymtableTest.test_assigned:  s    		((-99;<		((/;;=>/;;=>		((4@@BC--c2>>@Ar   c                 0   t        j                   ddd      }|j                         d   }| j                  |j                  d      j	                                | j                  |j                  d      j                                | j                  |j                  d      j                                t        j                   ddd      }|j                         d   }| j                  |j                  d      j	                                | j                  |j                  d      j                                t        j                   ddd      }| j                  |j                  d      j                                t        j                   ddd      }y )	Nzdef f():
    x: int
testr   r   rB   zdef f():
    x = 1
zglobal x
x: intz=def g():
    x = 2
    def f():
        nonlocal x
    x: int)symtabler   r0   rQ   r[   is_annotatedr.   rR   )r'   st1st2st3st4st5st6s          r
   test_annotatedzSymtableTest.test_annotatedA  s9    8&&I #

30023

34467C2245 7H #

30023C5578  2FFC

31134  !-
 !'0r   c                 t    | j                  | j                  j                  d      j                                y )Nsys)r0   r!   rQ   is_importedr&   s    r
   test_importedzSymtableTest.test_importedZ  s$    .::<=r   c                 r   | j                  | j                  j                         d       | j                  | j                  j                         d       | j                  | j                  j	                  d      j                         d       | j                  | j
                  j                         d       y )Nr!   r   rB   r   )r    r!   r   r   rQ   r   r&   s    r
   	test_namezSymtableTest.test_name]  s    **,e4++-v6))#.7793?++-v6r   c           
           j                   j                  j                         d       t        j                  t        dd      }t        |d      } j                  |j                         d        fd}d}|D ]v  } j                  |      5   ||d	       d d d         j                  |d
      5   |dj                  |df      d	        |dj                  d|f      d	       d d d        x dD ]  }d| dd| dd| dd| dfD ]}  } j                  |      5   ||d       d d d        |D ]R  } j                  ||      5   |dj                  ||f      d        |dj                  ||f      d       d d d        T   y # 1 sw Y   xY w# 1 sw Y   -xY w# 1 sw Y   ~xY w# 1 sw Y   xY w)N)r   r   r   ComplexClass)r   a_method_pep_695an_async_methodan_async_method_pep_695a_classmethoda_classmethod_pep_695an_async_classmethodan_async_classmethod_pep_695a_staticmethoda_staticmethod_pep_695an_async_staticmethodan_async_staticmethod_pep_695a_fakemethoda_fakemethod_pep_695an_async_fakemethodan_async_fakemethod_pep_695glob_unassigned_methglob_unassigned_meth_pep_695glob_unassigned_async_meth"glob_unassigned_async_meth_pep_695glob_assigned_methglob_assigned_meth_pep_695glob_assigned_async_meth glob_assigned_async_meth_pep_695c                     t        j                  | d      }t        j                  d| dd      }t        |d      }j	                  |j                         |       y )Nz    z	class A:
r   r   A)textwrapindentr~   r   r    get_methods)bodyexpected_methodsindentedr!   thisr'   s        r
   
check_bodyz7SymtableTest.test_class_get_methods.<locals>.check_body  sT    tW5H##j
$;S&ICc3'DT--/1ABr   )zx = (x for x in [])zx = (x async for x in [])zgenexpr = (x for x in [])zgenexpr = (x async for x in []))gen T)r   isvar
zgenexpr = 1)z()z(x)z(x, y)z(z: T)zdef genexprz:passzasync def genexprzdef genexpr[T]zasync def genexpr[T])rK   )genexpr)r   rK   )r    r   r   r~   TEST_COMPLEX_CLASS_CODEr   subTestjoin)r'   r!   r   r   GENEXPRSr   	paramlistrK   s   `       r
   test_class_get_methodsz#SymtableTest.test_class_get_methodsc  s   ..0-@ 7fE#~.))+ .
 	,	C
 C#&3# ' #T2499c=%9:B?499mS%9:B? 32  ;Ii[.#I;e4 51&yk7	 \\t\,t\2 - $C#D9"499c4[#9<H"499dC[#9<H :9 $ ; '& 32 -,
 :9s0   
F65F%
F,5F8	F	F)	,F58Gc                      fd} |dd        |dd       t        j                   ddd        j                  t              5  t        j                   dt        d      d       d d d         j                  t              5  t        j                   dt	        d      d       d d d         j                  t              5  t        j                   dt        d      d       d d d        y # 1 sw Y   xY w# 1 sw Y   TxY w# 1 sw Y   y xY w)	Nc                 2   	 t        j                   | dd       j                  d|        y # t        $ r^}j                  |j                  d       j                  |j
                  d       j                  |j                  |       Y d }~y d }~ww xY w)Nr   r   zno SyntaxError for    )r~   failSyntaxErrorr    filenamelinenooffset)
brokencoder   er'   s      r
   checkfilenamez9SymtableTest.test_filename_correct.<locals>.checkfilename  s}    C!!*ff= 		ZAB  3  V4  1-  6223s   / 	BABBzdef f(x): foo)(r9   zdef f(x): global x   passs   spamr   )r~   rl   	TypeError	bytearray
memoryviewlist)r'   r   s   ` r
   test_filename_correctz"SymtableTest.test_filename_correct  s    	C 	',*B/&'62y)fi&8&A *y)fj&96B *y)fd7mV< *)	 *)))))s$   !C+!C7!D+C47D Dc                 2    t        j                   ddd      }y )N42r   evalr~   r'   symbolss     r
   	test_evalzSymtableTest.test_eval  s    ##D#v6r   c                 2    t        j                   ddd      }y )Nr   r   singler   r   s     r
   test_singlezSymtableTest.test_single  s    ##D#x8r   c                 2    t        j                   ddd      }y )Nzdef f(x): return xr   r   r   r   s     r
   	test_execzSymtableTest.test_exec  s    ##$8#vFr   c                     t        j                   t        j                  d      dd      }| j                  t	        |d             d}t        j                   |dd      }| j                  t	        |d             y )Nutf8r   r   r   s+   # -*- coding: iso8859-15 -*-
class : pass
u   Ž)r~   	TEST_CODEencodeassertIsNotNoner   )r'   r!   codes      r
   
test_byteszSymtableTest.test_bytes  sd    	 0 0 8#vFZV45Bc62ZX67r   c                     | j                  t        | j                        d       | j                  t        | j                        d       y )Nz<SymbolTable for module ?>z$<Function SymbolTable for spam in ?>)r    strr!   r   r&   s    r
   test_symtable_reprzSymtableTest.test_symtable_repr  s4    TXX(DETYY)OPr   c                     d| j                   j                          d| j                   j                          d}| j                  t	        | j                   j
                        |       y )Nz<symtable entry top(z), line >)r!   r+   r:   r    repr_tablerX   s     r
   test_symtable_entry_reprz%SymtableTest.test_symtable_entry_repr  sN    )$((//*;)<HTXXEXEXEZD[[\]dhhoo.9r   N)0__name__
__module____qualname__r~   r   r!   r   r   r   r   r   r   r   r   r   r#   r   r$   r   r%   r   r(   r,   r1   r4   r7   r;   rM   rT   rY   r\   r_   rb   rf   rn   rx   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r      sV   
(

IsF
3Cc6"D$
+Hc6"D$
+H&67N
S%
 CsG$Ec>2L#L.Ac>2L#L.AS-0K";>;$A= 
92
32
5<
QHP=@
?
A?"B02>7CIJ=,79G8Q:r   r   __main__)__doc__r   r~   unittestr   r   r   TestCaser   r   mainr   r   r
   <module>r      s[      +	Zp fe:8$$ e:P	 zHMMO r   