
    0hh-Q                         S SK r S SKrS SKrS SKJr  S SKJr  SrSrS r	 " S S\R                  5      r " S	 S
\R                  5      r\S:X  a  \R                  " 5         gg)    N)support)	os_helpera  
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, U: (int, str) = 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                 b    U R                  5        H  nUR                  5       U:X  d  M  Us  $    g N)get_childrenget_name)blocknamechs      ;/opt/python-3.13.8/usr/lib/python3.13/test/test_symtable.py
find_blockr      s(      ";;=D I #    c                      \ rS rSr\R                  " \SS5      r\" \S5      r\" \S5      r	\" \S5      r
\" \
S5      r\" \
S5      r\" \S	5      r\" \S
5      r\" \S5      r\" \S5      r\" \S5      r\" \S5      r\" \S5      r\" \S5      r\" \S5      r\" \S5      rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S r$S r%S r&S  r'S! r(S" r)S# r*S$ r+S% r,S& r-S' r.S( r/S) r0S* r1S+ r2S,r3g-).SymtableTest   ?execMinea_methodspaminternalother_internalfooAliasGenericAliasgeneric_spamGenericMineTUc                    U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R
                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                   R                  5       S5        g )Nmoduleclassfunctionz
type aliasztype parametersztype variable)assertEqualtopget_typer   r   r   r   r   r   r   GenericAlias_innerr   generic_spam_innerr   GenericMine_innerr   r   selfs    r   	test_typeSymtableTest.test_type   s   **,h7++-w7//1:>++-z://1:>**,j9,,.=**3357HI0099;\J**3357HI0099;ZH))2246GH//88:GD*O<*O<r   c                 L   U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R
                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        g )Nr   )assertGreaterr%   get_idr   r   r   r   r   r   r   r   r   r*   s    r   test_id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                     U R                  U R                  R                  5       5        U R                  U R                  R                  5       5        g r   )assertFalser%   is_optimized
assertTruer   r*   s    r   test_optimizedSymtableTest.test_optimized   s6    ..01		..01r   c                 L   U R                  U R                  R                  5       5        U R                  U R                  R                  5       5        U R                  U R                  R                  5       5        U R                  U R                  R                  5       5        g r   )r4   r%   	is_nestedr   r   r6   r   r*   s    r   test_nestedSymtableTest.test_nested   sl    ++-.,,./,,.///12r   c                     U R                  U R                  R                  5       5        U R                  U R                  R                  5       5        U R	                  U R
                  R                  5       5        g r   )r6   r%   has_childrenr   r4   r   r*   s    r   test_childrenSymtableTest.test_children   sO    --/0		..01..01r   c                     U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        g )Nr      )r$   r%   
get_linenor   r*   s    r   test_linenoSymtableTest.test_lineno   s<    ,,.2--/4r   c                 v   U R                   nU R                  [        UR                  5       5      / SQ5        / SQnU R                  [        UR	                  5       5      U5        U R                  [        UR                  5       5      / SQ5        U R                  U R                  R                  5       S5        g )N)abkwvar)rG   rH   r   rI   r   some_varrJ   x)barglobsome_assigned_global_var)rL   )r   r$   sortedget_parameters
get_localsget_globalsr   	get_frees)r+   funcexpecteds      r   test_function_infoSymtableTest.test_function_info   s    yy 3 3 568OPY 12H= 0 0 235`a002F;r   c                    U R                  U R                  R                  S5      R                  5       5        U R	                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R	                  U R                  R                  S5      R                  5       5        U R	                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        g )NrN   rM   rL   instance_varsome_non_assigned_global_varrO   )	r6   r   lookup	is_globalr4   is_declared_globalr   r   r%   r*   s    r   test_globals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                 <   U R                  U R                  R                  S5      R                  5       5        U R	                  U R
                  R                  S5      R                  5       5        SnU R                  U R
                  R                  5       U5        g )NrK   )rK   )r4   r   r\   is_nonlocalr6   r   r$   get_nonlocalsr+   rV   s     r   test_nonlocalSymtableTest.test_nonlocal  sr    ))*5AACD++22:>JJLM ,,::<hGr   c                    U R                  U R                  R                  S5      R                  5       5        U R	                  U R                  R                  S5      R                  5       5        U R                  U R
                  R                  S5      R                  5       5        U R                  U R
                  R                  S5      R                  5       5        g )NrL   rM   r[   rO   )r6   r   r\   is_localr4   r%   r*   s    r   
test_local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    U R                  U R                  R                  S5      R                  5       5        g )NrL   )r6   r   r\   is_freer*   s    r   	test_freeSymtableTest.test_free  s&    ,,S199;<r   c                 T   U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        g )NrL   r   )r6   r   r\   is_referencedr   r4   r*   s    r   test_referencedSymtableTest.test_referenced  sp    ,,S1??AB		((4BBDE))#.<<>?r   c                     S H;  nU R                  U R                  R                  U5      R                  5       5        M=     U R	                  U R                  R                  S5      R                  5       5        g )N)rG   rJ   rI   rL   )r6   r   r\   is_parameterr4   )r+   syms     r   test_parametersSymtableTest.test_parameters"  sV    %COODII,,S1>>@A &))#.;;=>r   c                    U R                  [        U R                  R                  5       5      [        U R                  R	                  5       5      5        U R                  [        U R                  R                  S5        g )Nnot_here)r$   lenr%   get_identifiersget_symbolsassertRaisesKeyErrorr\   r*   s    r   test_symbol_lookupSymtableTest.test_symbol_lookup'  sU    TXX5578TXX1134	6 	(DHHOOZ@r   c                    U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R
                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R
                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       U R
                  L 5        U R                  R                  S5      nU R                  [        UR                  5       5      S5        U R                  [        UR                  5        U R                  R                  S5      nU R                  [        UR                  5       5      S	5        U R                  [        UR                  5        g )
Nr   r   r   r   namespace_testrL      rN   r   )r6   r%   r\   is_namespacer   r   r4   get_namespacer$   rz   get_namespacesr}   
ValueError)r+   ns_test	ns_test_2s      r   test_namespaces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   U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        U R                  U R
                  R                  S5      R                  5       5        U R                  U R                  R                  S5      R                  5       5        g )NrL   rM   r   r   )r6   r   r\   is_assignedr%   r   r4   r   r*   s    r   test_assignedSymtableTest.test_assigned>  s    		((-99;<		((/;;=>/;;=>		((4@@BC--c2>>@Ar   c                 8   [         R                   " SSS5      nUR                  5       S   nU R                  UR                  S5      R	                  5       5        U R                  UR                  S5      R                  5       5        U R                  UR                  S5      R                  5       5        [         R                   " SSS5      nUR                  5       S   nU R                  UR                  S5      R	                  5       5        U R                  UR                  S5      R                  5       5        [         R                   " SSS5      nU R                  UR                  S5      R                  5       5        [         R                   " SSS5      ng )	Nzdef f():
    x: int
testr   r   rL   zdef f():
    x = 1
zglobal x
x: intz=def g():
    x = 2
    def f():
        nonlocal x
    x: int)symtabler   r6   r\   rh   is_annotatedr4   r]   )r+   st1st2st3st4st5st6s          r   test_annotatedSymtableTest.test_annotatedE  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    U R                  U R                  R                  S5      R                  5       5        g )Nsys)r6   r%   r\   is_importedr*   s    r   test_importedSymtableTest.test_imported^  s$    .::<=r   c                 r   U R                  U R                  R                  5       S5        U R                  U R                  R                  5       S5        U R                  U R                  R	                  S5      R                  5       S5        U R                  U R
                  R                  5       S5        g )Nr%   r   rL   r   )r$   r%   r   r   r\   r   r*   s    r   	test_nameSymtableTest.test_namea  s    **,e4++-v6))#.7793?++-v6r   c           
        ^  T R                  T R                  R                  5       S5        [        R                  " [        SS5      n[        US5      nT R                  UR                  5       S5        U 4S jnSnU Hq  nT R                  US9   U" US	5        S S S 5        T R                  US
S9   U" SR                  US45      S	5        U" SR                  SU45      S	5        S S S 5        Ms     S H  nSU S3SU S3SU S3SU S34 Hw  nT R                  US9   U" US5        S S S 5        U HM  nT R                  XWS9   U" SR                  XW45      S5        U" SR                  Xu45      S5        S S S 5        MO     My     M     g ! , (       d  f       N= f! , (       d  f       GM1  = f! , (       d  f       N= f! , (       d  f       M  = f)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                    > [         R                  " U S5      n[        R                  " SU 3SS5      n[        US5      nTR	                  UR                  5       U5        g )Nz    z	class A:
r   r   A)textwrapindentr   r   r$   get_methods)bodyexpected_methodsindentedr%   thisr+   s        r   
check_body7SymtableTest.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 [])z3type x[genexpr = (x for x in [])] = (x for x in [])z?type x[genexpr = (x async for x in [])] = (x async for x in [])zgenexpr = (x for x in [])zgenexpr = (x async for x in [])z9type genexpr[genexpr = (x for x in [])] = (x for x in [])zEtype genexpr[genexpr = (x async for x in [])] = (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])rU   )genexpr)r   rU   )r$   r   r   r   TEST_COMPLEX_CLASS_CODEr   subTestjoin)r+   r%   r   r   GENEXPRSr   	paramlistrU   s   `       r   test_class_get_methods#SymtableTest.test_class_get_methodsg  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#9"499c[#9<H"499d[#9<H :9 $ ; '& 32 -,
 :9s0   
F25F 
F23G	
F	
F/	2
G 
Gc                 F  ^  U 4S jnU" SS5        U" SS5        [         R                   " SSS5        T R                  [        5         [         R                   " S[        S5      S5        S S S 5        T R                  [        5         [         R                   " S[	        S5      S5        S S S 5        T R                  [        5         [         R                   " S[        S5      S5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N_= f! , (       d  f       g = f)	Nc                 8  >  [         R                   " U SS5        TR                  SU < 35        g ! [         a^  nTR                  UR                  S5        TR                  UR
                  S5        TR                  UR                  U5         S nAg S nAff = f)Nr   r   zno SyntaxError for    )r   failSyntaxErrorr$   filenamelinenooffset)
brokencoder   er+   s      r   checkfilename9SymtableTest.test_filename_correct.<locals>.checkfilename  s}    C!!*ff= 		ZAB  3  V4  1-  6223s   1 
BABBzdef f(x): foo)(rB   zdef f(x): global x   passs   spamr   )r   r}   	TypeError	bytearray
memoryviewlist)r+   r   s   ` r   test_filename_correct"SymtableTest.test_filename_correct  s    	C 	',*B/&'62y)fi&8&A *y)fj&96B *y)fd7mV< *)	 *)))))s$   "C0"D"D0
C>
D
D c                 4    [         R                   " SSS5      ng )N42r   evalr   r+   symbolss     r   	test_evalSymtableTest.test_eval  s    ##D#v6r   c                 4    [         R                   " SSS5      ng )Nr   r   singler   r   s     r   test_singleSymtableTest.test_single  s    ##D#x8r   c                 4    [         R                   " SSS5      ng )Nzdef f(x): return xr   r   r   r   s     r   	test_execSymtableTest.test_exec  s    ##$8#vFr   c                     [         R                   " [        R                  S5      SS5      nU R                  [	        US5      5        Sn[         R                   " USS5      nU R                  [	        US5      5        g )Nutf8r   r   r   s+   # -*- coding: iso8859-15 -*-
class : pass
u   Ž)r   	TEST_CODEencodeassertIsNotNoner   )r+   r%   codes      r   
test_bytesSymtableTest.test_bytes  sd    	 0 0 8#vFZV45Bc62ZX67r   c                     U R                  [        U R                  5      S5        U R                  [        U R                  5      S5        g )Nz<SymbolTable for module ?>z$<Function SymbolTable for spam in ?>)r$   strr%   r   r*   s    r   test_symtable_reprSymtableTest.test_symtable_repr  s4    TXX(DETYY)OPr   c                    U R                  [        U R                  R                  S5      5      S5        U R                  [        U R                  R                  S5      5      S5        U R                  [        U R                  R                  S5      5      S5        U R                  [        U R                  R                  S5      5      S5        U R                  [        U R                  R                  S	5      5      S
5        U R                  [        U R                  R                  S5      5      S5        U R                  [        U R
                  R                  S5      5      S5        g )NrN   z%<symbol 'glob': GLOBAL_IMPLICIT, USE>rM   z5<symbol 'bar': GLOBAL_EXPLICIT, DEF_GLOBAL|DEF_LOCAL>rG   z<symbol 'a': LOCAL, DEF_PARAM>r   z)<symbol 'internal': LOCAL, USE|DEF_LOCAL>r   z+<symbol 'other_internal': LOCAL, DEF_LOCAL>rL   z<symbol 'x': FREE, USE>rK   z5<symbol 'some_var': FREE, USE|DEF_NONLOCAL|DEF_LOCAL>)r$   reprr   r\   r   r   r*   s    r   test_symbol_reprSymtableTest.test_symbol_repr  s   dii..v67@	Bdii..u56P	Rdii..s349	;dii..z:;D	Fdii../?@AF	Hdmm223782	4d1188DEP	Rr   c                     SU R                   R                  5        SU R                   R                  5        S3nU R                  [	        U R                   R
                  5      U5        g )Nz<symtable entry top(z), line >)r%   r0   rC   r$   r  _tablerd   s     r   test_symtable_entry_repr%SymtableTest.test_symtable_entry_repr  sN    )$((//*;)<HTXXEXEXEZD[[\]dhhoo.9r   r   N)4__name__
__module____qualname____firstlineno__r   r   r%   r   r   r   r   r   r   r   r   r   r'   r   r(   r   r)   r   r   r,   r1   r7   r;   r?   rD   rW   r_   re   ri   rm   rq   rv   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  __static_attributes__r   r   r   r   r      sf   


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;$A="
92
32
5<
QHP=@
?
A?"B02>7GIR=,79G8QR :r   r   c                   $    \ rS rSrSrS rS rSrg)CommandLineTesti  Nc                    [         R                  nU R                  [         R                  U5        [	        US5       nUR                  [        5        S S S 5        [        R                  " 5        n[        R                  " U/5        S S S 5        WR                  5       nU R                  SU5        U R                  SU5        UR                  5       nU R                  SU< S3U5        U R                  SU5        U R                  SU5        U R                  SU5        U R                  S	U5        g ! , (       d  f       N= f! , (       d  f       N= f)
Nwz

z


z"symbol table for module from file :z"    local symbol 'glob': def_localz*        global_implicit symbol 'glob': usez"    local symbol 'spam': def_localz%    symbol table for function 'spam':)r   TESTFN
addCleanupunlinkopenwriter   r   captured_stdoutr   maingetvalueassertInassertNotIn
splitlines)r+   r   fstdoutoutliness         r   	test_fileCommandLineTest.test_file  s    ##	(((3(C AGGI !$$&&MM8*% 'oofc"3' :8,aH%P:EBBEJ:EB=uE ! &&s   D40E4
E
Ec                    [         R                  " 5        nUR                  [        5        UR	                  S5        [         R
                  " 5        n[        R                  " / 5        S S S 5        WR                  5       nUR	                  S5        [         R
                  " 5        n[        R                  " S/5        S S S 5        U R                  UR                  5       U5        S S S 5        WR                  5       nU R                  SU5        g ! , (       d  f       N= f! , (       d  f       Nj= f! , (       d  f       NS= f)Nr   -z,symbol table for module from file '<stdin>':)r   captured_stdinr  r   seekr  r   r  r  r$   r   r  )r+   stdinr"  r#  r$  s        r   
test_stdinCommandLineTest.test_stdin  s    ##%KK	"JJqM((*fb! +//#CJJqM((*fse$ +V__.4 &  DeL +* +* &%s;   <D4D)>D4'D#?(D4
D 	D4#
D1	-D44
Er   )r  r  r  r  maxDiffr%  r,  r  r   r   r   r  r    s    GF"Mr   r  __main__)r   r   unittestr   r   test.supportr   r   r   r   TestCaser   r  r  r  r   r   r   <module>r3     so   
     "+	Zp f{:8$$ {:|	 Mh''  MF zMMO r   