L idZddlmZddlZddlZddlmZddlmZejGddZ Gdd Z d d Z y) z*Find functions and classes in Python code.) annotationsN)cast) CodeRegionc0eZdZUdZded<ded<ded<y)Contextz0The nested named context of a function or class.strnamekindzset[int]linesN)__name__ __module__ __qualname____doc____annotations__V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/coverage/regions.pyrrs: I I OrrcHeZdZdZd dZd dZd dZd dZd dZddZ ddZ y ) RegionFinderzAn ast visitor that will find and track regions of code. Functions and classes are tracked by name. Results are in the .regions attribute. c g|_g|_yN)regionscontextselfs r__init__zRegionFinder.__init__ s)+ &( rcL|jtj|y)zCParse `source` and walk the ast to populate the .regions attribute.N) handle_nodeastparse)rsources r parse_sourcezRegionFinder.parse_source$s 6*+rcFdjd|jDS)z6Get the current fully qualified name we're processing..c34K|]}|jywr)r ).0cs r z,RegionFinder.fq_node_name..*s515s)joinrrs r fq_node_namezRegionFinder.fq_node_name(sxx5 555rct|tjtjfr|j |yt|tj r|j |y|j|y)zRecursively handle any node.N) isinstancer FunctionDefAsyncFunctionDefhandle_FunctionDefClassDefhandle_ClassDefhandle_node_body)rnodes rrzRegionFinder.handle_node,sS dS__c.B.BC D  # #D ) cll +   &  ! !$ 'rcJt|ddD]}|j|y)z9Recursively handle the nodes in this node's body, if any.bodyrN)getattrr)rr3 body_nodes rr2zRegionFinder.handle_node_body5s( vr2 (I   Y ' (rc tt|jdjt t |jdj dz}|jr>|jdjdk(r"|jdxj|zc_ t|jD](}|jdk(s|xj|zc_ n|jjt|jd||jjtd|j!|j||j#||jj%y)z Called for `def` or `async def`.rclassfunctionr r startr N)setranger5linenorint end_linenorr r reversedappendrr rrr*r2poprr3r ancestors rr/zRegionFinder.handle_FunctionDef:sE$))A,--tC29Q9Q/RUV/VWX <?  &&(kk    d#  . (H}}'%' (rN)returnNone)r!rrJrK)rJr)r3zast.ASTrJrK)r3z&ast.FunctionDef | ast.AsyncFunctionDefrJrK)r3z ast.ClassDefrJrK) r r rrrr"r*rr2r/r1rrrrrs*),6(( .(rrcPt}|j||jS)a]Find function and class regions in source code. Analyzes the code in `source`, and returns a list of :class:`CodeRegion` objects describing functions and classes as regions of the code:: [ CodeRegion(kind="function", name="func1", start=8, lines={10, 11, 12}), CodeRegion(kind="function", name="MyClass.method", start=30, lines={34, 35, 36}), CodeRegion(kind="class", name="MyClass", start=25, lines={34, 35, 36}), ] The line numbers will include comments and blank lines. Later processing will need to ignore those lines as needed. Nested functions and classes are excluded from their enclosing region. No line should be reported as being part of more than one function, or more than one class. Lines in methods are reported as being in a function and in a class. )rr"r)r!rfs r code_regionsrNhs!* BOOF ::r)r!rrJzlist[CodeRegion]) r __future__rr dataclassestypingrcoverage.pluginr dataclassrrrNrrrrTsJ1" & M(M(`r