
    Vh	                     r    U d Z ddlZddlmZ i Zeeeeef   f   ed<   ddZ	deddfdZ
ded	edee   fd
Zy)a  
This module provides functionality for caching and looking up fully qualified function
and class names from Python source files by line number.

It uses Python's tokenize module to parse source files and tracks function/class
definitions along with their nesting to build fully qualified names (e.g. 'class.method'
or 'module.function'). The results are cached in a two-level dictionary mapping:

    filename -> (line_number -> fully_qualified_name)

Example usage:
    name = get_funcname("myfile.py", 42)  # Returns name of function/class at line 42
    clearcache()  # Clear the cache if file contents have changed

The parsing is done lazily when a file is first accessed. Invalid Python files or
IO errors are handled gracefully by returning empty cache entries.
    N)Optionalcachereturnc                  ,    t         j                          y N)r   clear     L/home/dcms/DCMS/lib/python3.12/site-packages/torch/_dynamo/funcname_cache.py
clearcacher      s    	KKMr
   filenamec                    	 t        j                  |       5 }t        t        j                  |j                              }d d d        i }d}d}g }t              D ](  \  }}|j                  t         j                  k(  r|dz  }n|j                  t         j                  k(  r4|dz  }|r||d   k(  r|j                          |j                  d      d   }n|j                  t         j                  k(  r|dz   t        |      k  rn||dz      j                  t         j                  k(  rK|j                   dk(  s|j                   dk(  r-|j#                  |       |r|dz  }|||dz      j                   z  }|||j$                  d   <   + |t        | <   y # 1 sw Y   SxY w# t
        t         j                  f$ r i t        | <   Y y w xY w)N r      .classdef)tokenizeopenlistgenerate_tokensreadlineOSError
TokenErrorr   	enumeratetypeINDENTDEDENTpop
rpartitionNAMElenstringappendstart)	r   ftokensresultcur_name
cur_indentsignificant_indentsitokens	            r   	_add_filer/      s   ]]8$ 	@(221::>?F	@  FHJ%'f% *5::(!OJZZ8??*!OJ"z5H5L'L#'')#..s3A6JJ(--'AF#q1u""hmm3(ELLE,A  &&z2Cq1u,,,H!)u{{1~+*. E(OK	@ 	@X(() hs(   F )F F FF "GGlinenoc                 Z    | t         vrt        |        t         |    j                  |d       S r   )r   r/   get)r   r0   s     r   get_funcnamer3   H   s)    u(?vt,,r
   )r   N)__doc__r   typingr   r   dictstrint__annotations__r   r/   r3   r	   r
   r   <module>r:      sg   $   $&tCc3h  %' ' 'T-3 - - -r
   