HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/coverage/__pycache__/parser.cpython-310.pyc
o

!we��@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZmZmZmZmZmZmZmZmZmZddlmZddlmZddlmZdd	lmZm Z dd
l!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(Gd
d�d�Z)Gdd�d�Z*Gdd�de�+dd��Z,Gdd�de�Z-ee'eeee.ee.ffZ/Gdd�d�Z0Gdd�de0�Z1Gdd�de0�Z2Gdd�de0�Z3Gdd �d e0�Z4Gd!d"�d"ej5�Z6d:d'd(�Z7Gd)d*�d*�Z8d+gZ9d;d/d0�Z:de;fd<d8d9�Z<dS)=zCode parsing for coverage.py.�)�annotationsN)�CodeType)�cast�Any�Callable�Dict�Iterable�List�Optional�Protocol�Sequence�Set�Tuple)�env)�code_objects)�short_stack)�NoSource�	NotPython)�
join_regex�	nice_pair)�generate_tokens)�TArc�TLineNoc@s�eZdZdZ			d1d2d	d
�Zd3dd�Zd4dd�Zd5dd�Zd6dd�Zd7dd�Z	d8d d!�Z
d4d"d#�Zd9d$d%�Zd4d&d'�Z
d:d)d*�Z	d;d<d/d0�ZdS)=�PythonParserz�Parse code to find executable lines, excluded lines, etc.

    This information is all based on static analysis: no code execution is
    involved.

    N�text�
Optional[str]�filename�exclude�return�Nonec
Cs�|s|sJd��|pd|_|dur||_n'ddlm}z||j�|_Wnty;}ztd|j�d|���|�d}~ww||_|j�d�|_t	�|_
t	�|_t	�|_t	�|_
t	�|_t	�|_d	|_i|_d|_d|_dS)
z�
        Source can be provided as `text`, the text itself, or `filename`, from
        which the text will be read.  Excluded lines are those that match
        `exclude`, a regex string.

        z*PythonParser needs either text or filenamez<code>Nr)�get_python_sourcezNo source for code: 'z': �
F)rr�coverage.pythonr �OSErrorrr�split�lines�set�
statements�excluded�raw_statements�raw_excluded�
raw_classdefs�raw_docstrings�show_tokens�
_multiline�	_all_arcs�_missing_arc_fragments)�selfrrrr �err�r3�H/home/arjun/projects/env/lib/python3.10/site-packages/coverage/parser.py�__init__&s.
��
zPythonParser.__init__�regexes�str�Set[TLineNo]cGsHt|�}t�|�}t�}t|jdd�D]\}}|�|�r!|�|�q|S)z�Find the lines matching one of a list of regexes.

        Returns a set of line numbers, the lines that contain a match for one
        of the regexes in `regexes`.  The entire line needn't match, just a
        part of it.

        ���start)r�re�compiler&�	enumerater%�search�add)r1r6�combined�regex_c�matches�i�ltextr3r3r4�lines_matchingfs


�zPythonParser.lines_matchingcCs�|jr
|�|j�|_d}d}d}d}tj}d}d}d}d}	|jdus$J�t|j�}
|
D]�\}}\}
}\}}}|jrLtdt	j
�||�t|
|f�||f�|tjkrV|d7}n�|tj
kr`|d8}n�|tjkrp|dkro|j�|
�n�|tjkr�|dkr�|	dkr�||jvp�|}|s�|r�|j�|�|}d}d}n^|d	kr�|r�||jvr�d}|r�|j�|�nH|d
vr�|	d7}	n?|dvr�|	d8}	n6|tjkr�|tjkr�|j�t|
|d��n |tjkr�|dur�||kr�t||d�D]}||j|<q�d}d}|���r|t	jk�rd}|du�r|
}|�r||k�rd}|�r|j�|�d}|}q+|�s2t|j|jd�}|j�|���tjj �rE|j�rGt!|j�|jd<dSdSdS)
zwParse the source to find the interesting facts about its lines.

        A handful of attributes are updated.

        rFNTz%10s %5s %-20r %rr9�class�:�@z([{z)]})r)"rrFr*�token�INDENTrrr-�print�tokenize�tok_name�getr�DEDENT�NAMEr+r@�OP�STRINGr,�update�range�NEWLINEr.�strip�COMMENT�
ByteParserrr)�_find_statementsr�
PYBEHAVIOR�module_firstline_1�min)r1�indent�exclude_indent�	excluding�excluding_decorators�prev_toktype�
first_line�empty�
first_on_line�nesting�tokgen�toktype�ttext�slineno�_�elinenorE�should_exclude�l�byte_parserr3r3r4�
_raw_parsevs�
�




�
�
�
�

�zPythonParser._raw_parse�linenorcCs2|dkr|j�||�}|S|j�||�}|S)zAReturn the first line number of the statement including `lineno`.r)r.rO)r1rqr3r3r4rc�s
�zPythonParser.first_line�linenos�Iterable[TLineNo]c��fdd�|D�S)z�Map the line numbers in `linenos` to the correct first line of the
        statement.

        Returns a set of the first lines.

        csh|]}��|��qSr3�rc��.0rn�r1r3r4�	<setcomp>�sz+PythonParser.first_lines.<locals>.<setcomp>r3)r1rrr3rxr4�first_lines�szPythonParser.first_linesr%cCs
|�|�S)z)Implement `FileReporter.translate_lines`.)rz)r1r%r3r3r4�translate_lines��
zPythonParser.translate_lines�arcs�Iterable[TArc]�	Set[TArc]crt)z(Implement `FileReporter.translate_arcs`.cs$h|]\}}��|���|�f�qSr3ru)rw�a�brxr3r4ry�s$z.PythonParser.translate_arcs.<locals>.<setcomp>r3)r1r}r3rxr4�translate_arcs�szPythonParser.translate_arcsc
Cs�z|��Wn4tjttfy:}z$t|d�r|j}n|jdd}td|j	�d�|jd�d|���|�d}~ww|�
|j�|_|j|j
B}|j|}|�
|�||_dS)z�Parse source text to find executable lines, excluded lines, etc.

        Sets the .excluded and .statements attributes, normalized to the first
        line of multi-line statements.

        rqr9rzCouldn't parse 'z' as Python source: z	 at line N)rprM�
TokenError�IndentationError�SyntaxError�hasattrrq�argsrrrzr*r(r,r)r')r1r2rq�ignore�startsr3r3r4�parse_source�s&
�����

zPythonParser.parse_sourcecCs&|jdur	|��|jdusJ�|jS)z�Get information about the arcs available in the code.

        Returns a set of line number pairs.  Line numbers have been normalized
        to the first line of multi-line statements.

        N)r/�_analyze_astrxr3r3r4r}s
zPythonParser.arcscCsjt|j|j|j�}|��t�|_|jD]\}}|�|�}|�|�}||kr.|j�	||f�q|j
|_dS)zkRun the AstArcAnalyzer and save its results.

        `_all_arcs` is the set of arcs in the code.

        N)�AstArcAnalyzerrr)r.�analyzer&r/r}rcr@�missing_arc_fragmentsr0)r1�aaa�l1�l2�fl1�fl2r3r3r4r�s

�zPythonParser._analyze_ast�Dict[TLineNo, int]cCsvt�t�}|��D]\}}|dkrq	||jvrq	||jvrq	||d7<q	|jD]}||vr8||d8<q*|S)zYGet a count of exits from that each line.

        Excluded lines are excluded.

        rr9)�collections�defaultdict�intr}r(r+)r1�exit_countsr�r�rnr3r3r4r�-s



�zPythonParser.exit_countsr;�end�
executed_arcs�Optional[Iterable[TArc]]c
Cs|jdur|��|jdusJ�|}|r/|dkr/||kr/||f|vr/||f|jvr/||}}|j�||fdg�}g}|D]D\}}|dur_|dkr]||f|jvrZ|�||�Sd}nd}|j|d�}d|�d|��}	|dur||	d	|j|d���7}	|�|	�q=d
�|�S)z5Provide an English sentence describing a missing arc.Nr�NNz didn't jump to the function exitzdidn't jump to line {lineno}�rqzline � z
, because � or )r0r�rO�missing_arc_description�format�append�join)
r1r;r�r��actual_start�fragment_pairs�msgs�smsg�emsg�msgr3r3r4r�Hs2
�

z$PythonParser.missing_arc_description)NNN)rrrrrrrr)r6r7rr8�rr)rqrrr)rrrsrr8)r%rsrr8)r}r~rr)rr)rr��N)r;rr�rr�r�rr7)�__name__�
__module__�__qualname__�__doc__r5rFrprcrzr{r�r�r}r�r�r�r3r3r3r4rs$�
@

g

	




�rc@s>eZdZdZ		dddd�Zddd�Zddd�Zddd�ZdS)rYz3Parse bytecode to understand the structure of code.Nrr7�code�Optional[CodeType]rrrrc
Csr||_|dur||_dS|dusJ�zt||ddd�|_WdSty8}ztd||j|jp/df�|�d}~ww)N�execT)�dont_inheritz5Couldn't parse '%s' as Python source: '%s' at line %dr)rr�r=r�rr�rq)r1rr�r�synerrr3r3r4r5ys 
�����zByteParser.__init__�Iterable[ByteParser]cs�fdd�t�j�D�S)z~Iterate over all the code objects nested within this one.

        The iteration includes `self` as its first value.

        c3s�|]
}t�j|d�VqdS))r�N)rYr�rw�crxr3r4�	<genexpr>�s�z+ByteParser.child_parsers.<locals>.<genexpr>)rr�rxr3rxr4�
child_parsers�szByteParser.child_parsersrsc
cs��t|jd�r|j��D]
\}}}|r|VqdS|jjddd�}|jjddd�}d}|jj}d}t||�D]\}}	|rK||krG|V|}||7}|	dkrS|	d8}	||	7}q8||kra|VdSdS)z�Yield the line numbers possible in this code object.

        Uses co_lnotab described in Python/compile.c to find the
        line numbers.  Produces a sequence: l0, l1, ...
        �co_linesrN�r9��)r�r�r��	co_lnotab�co_firstlineno�zip)
r1rk�line�byte_increments�line_increments�
last_line_num�line_num�byte_num�	byte_incr�	line_incrr3r3r4�
_line_numbers�s0���

�zByteParser._line_numbersccs"�|��D]	}|��EdHqdS)z�Find the statements in `self.code`.

        Produce a sequence of line numbers that start statements.  Recurses
        into all code objects reachable from `self.code`.

        N)r�r�)r1�bpr3r3r4rZ�s��zByteParser._find_statementsr�)rr7r�r�rrrr)rr�)rrs)r�r�r�r�r5r�r�rZr3r3r3r4rYvs�

rYcs$eZdZdZd
d�fdd	�
Z�ZS)�ArcStarta�The information needed to start an arc.

    `lineno` is the line number the arc starts from.

    `cause` is an English text fragment used as the `startmsg` for
    AstArcAnalyzer.missing_arc_fragments.  It will be used to describe why an
    arc wasn't executed, so should fit well into a sentence of the form,
    "Line 17 didn't run because {cause}."  The fragment can include "{lineno}"
    to have `lineno` interpolated into it.

    Nrqr�causerrcst��|||�Sr�)�super�__new__)�clsrqr���	__class__r3r4r���zArcStart.__new__r�)rqrr�rrr�)r�r�r�r�r��
__classcell__r3r3r�r4r��sr��Arcz
lineno, causec@s eZdZdZ		d
ddd�ZdS)�	TAddArcFnz&The type for AstArcAnalyzer.add_arc().Nr;rr�r�rr�rrcCsdSr�r3�r1r;r�r�r�r3r3r4�__call__�szTAddArcFn.__call__r��
r;rr�rr�rr�rrr)r�r�r�r�r�r3r3r3r4r��s
�r�c@s8eZdZdZddd	�Zdd
d�Zddd
�Zddd�ZdS)�Blocka;
    Blocks need to handle various exiting statements in their own ways.

    All of these methods take a list of exits, and a callable `add_arc`
    function that they can use to add arcs if needed.  They return True if the
    exits are handled, or False if the search should continue up the block
    stack.
    �exits�
Set[ArcStart]�add_arcr�r�boolcC�t�)zProcess break exits.��AssertionError�r1r�r�r3r3r4�process_break_exits��zBlock.process_break_exitscCr�)zProcess continue exits.r�r�r3r3r4�process_continue_exits�r�zBlock.process_continue_exitscC�dS)zProcess raise exits.Fr3r�r3r3r4�process_raise_exits��zBlock.process_raise_exitscCr�)zProcess return exits.Fr3r�r3r3r4�process_return_exits�r�zBlock.process_return_exitsN�r�r�r�r�rr�)r�r�r�r�r�r�r�r�r3r3r3r4r��s
	

r�c@s.eZdZdZddd�Zdd
d�Zddd�ZdS)�	LoopBlockz@A block on the block stack representing a `for` or `while` loop.r;rrrcCs||_t�|_dSr�)r;r&�break_exits�r1r;r3r3r4r5szLoopBlock.__init__r�r�r�r�r�cCs|j�|�dS�NT)r�rTr�r3r3r4r�szLoopBlock.process_break_exitscCs |D]}||j|j|j�qdSr�)rqr;r��r1r�r��xitr3r3r4r�sz LoopBlock.process_continue_exitsN�r;rrrr�)r�r�r�r�r5r�r�r3r3r3r4r��s


r�c@s.eZdZdZddd	�Zddd�Zddd�ZdS)�
FunctionBlockz>A block on the block stack representing a function definition.r;r�namer7rrcCs||_||_dSr��r;r�)r1r;r�r3r3r4r5s
zFunctionBlock.__init__r�r�r�r�r�cC�,|D]}||j|j|jd|j���qdS)Nzdidn't except from function T�rqr;r�r�r�r3r3r4r��
�z!FunctionBlock.process_raise_exitscCr�)Nzdidn't return from function Tr�r�r3r3r4r�!r�z"FunctionBlock.process_return_exitsN)r;rr�r7rrr�)r�r�r�r�r5r�r�r3r3r3r4r�s


r�c@sBeZdZdZddd�Zddd�Zddd�Zddd�Zddd�ZdS)�TryBlockz6A block on the block stack representing a `try` block.�
handler_start�Optional[TLineNo]�final_startrrcCs0||_||_t�|_t�|_t�|_t�|_dSr�)r�r�r&�
break_from�
continue_from�
raise_from�return_from)r1r�r�r3r3r4r5,szTryBlock.__init__r�r�r�r�r�cC�|jdur
|j�|�dSdS�NTF)r�r�rTr�r3r3r4r�9�
zTryBlock.process_break_exitscCr�r)r�r�rTr�r3r3r4r�?rzTryBlock.process_continue_exitscCsH|jdur|D]}||j|j|j�qdS|jdusJ�|j�|�dSr�)r�rqr�r�r�rTr�r3r3r4r�Es
�zTryBlock.process_raise_exitscCr�r)r�r�rTr�r3r3r4r�NrzTryBlock.process_return_exitsN)r�r�r�r�rrr�)	r�r�r�r�r5r�r�r�r�r3r3r3r4r�*s



	r�c@sPeZdZdZddd�Z	dddd�Zddd�Zddd�Zddd�Zddd�Z	dS)�	WithBlockz7A block on the block stack representing a `with` block.r;rrrcCs.tjjsJ�||_t�|_t�|_t�|_dSr�)rr[�exit_through_withr;r&r�r�r�r�r3r3r4r5Ws
zWithBlock.__init__Nr�r�r�r��from_set�Optional[Set[ArcStart]]r�cCs2|D]}||j|j|j�q|dur|�|�dS)z*Helper to process the four kinds of exits.NT)rqr;r�rT)r1r�r�rr�r3r3r4�_process_exitses

zWithBlock._process_exitscC�|�|||j�Sr�)rr�r�r3r3r4r�rr�zWithBlock.process_break_exitscCrr�)rr�r�r3r3r4r�ur�z WithBlock.process_continue_exitscCs|�||�Sr�)rr�r3r3r4r�x�zWithBlock.process_raise_exitscCrr�)rr�r�r3r3r4r�{r�zWithBlock.process_return_exitsr�r�)r�r�r�r�rrrr�r�)
r�r�r�r�r5rr�r�r�r�r3r3r3r4rUs
�


rc@seZdZdZd	dd�ZdS)
�NodeListz�A synthetic fictitious node, containing a sequence of nodes.

    This is used when collapsing optimized if-statements, to represent the
    unconditional execution of one of the clauses.

    �body�Sequence[ast.AST]rrcCs||_|dj|_dS�Nr)r
rq)r1r
r3r3r4r5�szNodeList.__init__N)r
rrr)r�r�r�r�r5r3r3r3r4r	sr	�nounr7r�)Callable[[AstArcAnalyzer, ast.AST], None]csd
�fdd�}|S)zPA function to make methods for expression-based callable _code_object__ methods.r1r��node�ast.ASTrrc	sJ|�|�}|�||dd��d|���|�||dd��d|���dS)Nzdidn't run the z	 on line zdidn't finish the )�
line_for_noder�)r1rr;�r
r3r4�!_code_object__expression_callable�s
"zG_make_expression_code_method.<locals>._code_object__expression_callableN)r1r�rrrrr3)r
rr3rr4�_make_expression_code_method�src@s�eZdZdZd�d
d�Zd�dd
�Z		d�d�dd�Zd�dd�Zd�dd�Zd�dd �Z	d�d"d#�Z
e	Zd�d%d&�Ze	Z
e	Zd�d(d)�Zd�d+d,�Zhd-�Zd�d/d0�Z		d�d�d7d8�Zd�d:d;�Zd�d=d>�Zd�d@dA�Zd�dCdD�Zd�dEdF�Zd�dHdI�Zd�dJdK�Zd�dLdM�Zd�dNdO�Zd�dQdR�Zd�dSdT�ZeZd�dVdW�Z d�dYdZ�Z!e!Z"eZ#eZ$d�d[d\�Z%e&j'd]kr�d�d_d`�Z(d�dadb�Z)d�ddde�Z*d�dgdh�Z+d�djdk�Z,d�dmdn�Z-d�dodp�Z.d�drds�Z/e/Z0d�dtdu�Z1d�dvdw�Z2e2Z3d�dydz�Z4e5d{�Z6e5d|�Z7e8j9j:r�e5d}�Z;e5d~�Z<e5d�Z=dSdS)�r�z>Analyze source text with an AST to find executable code paths.rr7r'r8�	multiline�Dict[TLineNo, TLineNo]rrcs�t�|�|_�fdd�|D�|_�|_tttj�	dd���}|r5t
d|j���t
d|j���t|j�t�|_
t�t�|_g|_tttj�	dd���|_dS)Ncsh|]}��||��qSr3)rOrv�rr3r4ry��z*AstArcAnalyzer.__init__.<locals>.<setcomp>�COVERAGE_AST_DUMPrzStatements: zMultiline map: �COVERAGE_TRACK_ARCS)�ast�parse�	root_noder'rr�r��os�environrOrL�ast_dumpr&r}r�r��listr��block_stack�debug)r1rr'r�dump_astr3rr4r5�s
zAstArcAnalyzer.__init__cCs>t�|j�D]}|jj}t|d|d�}|dur||�qdS)z�Examine the AST tree from `root_node` to determine possible arcs.

        This sets the `arcs` attribute to be a set of (from, to) line number
        pairs.

        �_code_object__N)r�walkrr�r��getattr)r1r�	node_name�code_object_handlerr3r3r4r��s��zAstArcAnalyzer.analyzeNr;rr�r�rr�c	Cst|jrtd|�d|�d|�d|���ttdd��|j�||f�|dus*|dur8|j||f�||f�dSdS)z@Add an arc, including message fragments to use if it is missing.z
Adding possible arc: (�, z): �
)�limitN)r#rLrr}r@r�r�r�r3r3r4r��s �zAstArcAnalyzer.add_arc�Iterable[Block]cCs
t|j�S)z.Yield the blocks in nearest-to-farthest order.)�reversedr"rxr3r3r4�nearest_blocks�r|zAstArcAnalyzer.nearest_blocksrrcCsD|jj}ttttjgtft|d|d��}|dur||�S|j	S)z}What is the right line number to use for this node?

        This dispatches to _line__Node functions where needed.

        �_line__N)
r�r�rr
rr�ASTrr'rq�r1rr(�handlerr3r3r4r�s�zAstArcAnalyzer.line_for_node�ast.FunctionDefcCs |jr|jdj}|S|j}|S)zSCompute first line number for things that can be decorated (classes and functions).r)�decorator_listrq)r1rrqr3r3r4�_line_decorated�s
�zAstArcAnalyzer._line_decorated�
ast.AssigncCs|�|j�Sr�)r�value�r1rr3r3r4�
_line__Assign�rzAstArcAnalyzer._line__Assign�ast.DictcCs2|jr|jddur|jdjS|jdjS|jSr)�keysrq�valuesr9r3r3r4�_line__Dict�s
zAstArcAnalyzer._line__Dict�ast.ListcCs|jr|�|jd�S|jSr)�eltsrrqr9r3r3r4�_line__ListszAstArcAnalyzer._line__List�
ast.ModulecCs&tjjrdS|jr|�|jd�SdS�Nr9r)rr[r\r
rr9r3r3r4�
_line__Modules
zAstArcAnalyzer._line__Module>�Expr�Pass�Assert�Assign�Delete�Global�Import�Nonlocal�	AnnAssign�	AugAssign�
ImportFromr�cCsp|jj}ttttjgttft	|d|d��}|dur!||�St
jr0||jvr0t
d|����t|�|��hS)a�Add the arcs for `node`.

        Return a set of ArcStarts, exits from this node to the next. Because a
        node represents an entire sub-tree (including its children), the exits
        from a node can be arbitrarily complex::

            if something(1):
                if other(2):
                    doit(3)
                else:
                    doit(5)

        There are two exits from line 1: they start at line 3 and line 5.

        �	_handle__Nz*** Unhandled: )r�r�rr
rrr1r
r�r'r�TESTING�
OK_TO_DEFAULT�RuntimeErrorrr2r3r3r4�add_arcss�
zAstArcAnalyzer.add_arcsr
r�
from_start�Optional[ArcStart]�prev_startsrc	Cs�|dur
|dus
J�|h}|D]7}|�|�}|j�||�}||jvr3|�|�}|dur,q|}|�|�}|D]}|�|j||j�q5|�|�}q|S)auAdd arcs for the body of a compound statement.

        `body` is the body node.  `from_start` is a single `ArcStart` that can
        be the previous line in flow before this body.  `prev_starts` is a set
        of ArcStarts that can be the previous line.  Only one of them should be
        given.

        Returns a set of ArcStarts, the exits from this body.

        N)	rrrOr'�find_non_missing_noder�rqr�rT)	r1r
rUrW�	body_noderqrc�maybe_body_node�
prev_startr3r3r4�
add_body_arcs>s 



zAstArcAnalyzer.add_body_arcs�Optional[ast.AST]cCsr|�|�}|j�||�}||jvr|Sttttjgttjft	|d|j
jd��}|dur5||�}|Sd}|S)aSearch `node` looking for a child that has not been optimized away.

        This might return the node you started with, or it will work recursively
        to find a child node in self.statements.

        Returns a node, or None if none of the node remains.

        �
_missing__N)rrrOr'rr
rrr1r'r�r�)r1rrqrc�
missing_fn�ret_noder3r3r4rX_s

��z$AstArcAnalyzer.find_non_missing_node�ast.IfcCs2|�t|j��}|r|S|jr|�t|j��SdSr�)rXr	r
�orelse)r1r�non_missingr3r3r4�_missing__If�szAstArcAnalyzer._missing__Ifr	cCsPg}|jD]}|�|�}|dur|�|�q|sdSt|�dkr$|dSt|�SrC)r
rXr��lenr	)r1r�non_missing_children�child�maybe_childr3r3r4�_missing__NodeList�s


�z!AstArcAnalyzer._missing__NodeList�	ast.WhilecCsd|�t|j��}|sdSt��}|j|_t��|_|j|j_d|j_t	|d�s)J�|j|_g|_
|S)N�Truer
)rXr	r
r�Whilerq�Name�test�idr�rb)r1r�
body_nodes�	new_whiler3r3r4�_missing__While�s

zAstArcAnalyzer._missing__WhilecCs2|jj}|dvr
dSt|tj�r|jdvrdSdS)z Is this a compile-time constant?)�Constant�NameConstant�Numru)rk�Falser�	__debug__rmN)r�r��
isinstancerrmro)r1rr(r3r3r4�is_constant_expr�s
zAstArcAnalyzer.is_constant_exprr�cC�&|��D]}|�||j�rdSqdS)z0Add arcs due to jumps from `exits` being breaks.N)r/r�r��r1r��blockr3r3r4r���
��z"AstArcAnalyzer.process_break_exitscCrz)z3Add arcs due to jumps from `exits` being continues.N)r/r�r�r{r3r3r4r��r}z%AstArcAnalyzer.process_continue_exitscCrz)z0Add arcs due to jumps from `exits` being raises.N)r/r�r�r{r3r3r4r��r}z"AstArcAnalyzer.process_raise_exitscCrz)z1Add arcs due to jumps from `exits` being returns.N)r/r�r�r{r3r3r4r��r}z#AstArcAnalyzer.process_return_exits�	ast.BreakcC�(|�|�}t|dd�}|�|h�t�S)Nz*the break on line {lineno} wasn't executed�r�)rr�r�r&)r1r�here�break_startr3r3r4�_handle__Break��
zAstArcAnalyzer._handle__Breakc
Cs|j}|j}|j}|r{d}|D]}|�|�}|dur$||kr$|�||�|}q|dus-J�|�||�|}tjjrit||dd��D]\}}|�|�|�|�|��qB|�|�|d�|�|�||�|d��|jr{|�|jd�}	|j	�
|	|	�}	|dus�J�t|�hS)zBAdd arcs for things that can be decorated (classes and functions).Nr9r���)rqr5rr�rr[�trace_decorator_line_againr�r
rrOr�)
r1r�	main_line�last�decs�dec_node�	dec_start�top�bot�
body_startr3r3r4�_handle_decorated�s.

z AstArcAnalyzer._handle_decorated�ast.ContinuecCr)Nz-the continue on line {lineno} wasn't executedr�)rr�r�r&)r1rr��continue_startr3r3r4�_handle__Continuer�z AstArcAnalyzer._handle__Continue�ast.ForcCs�|�|j�}|j�t|d��t|dd�}|j|j|d�}|D]}|�|j	||j
�q|j��}t|t�s7J�|j
}t|dd�}|jrQ|j|j|d�}||O}|S|�|�|S)Nr:z'the loop on line {lineno} never startedr��rUz)the loop on line {lineno} didn't complete)r�iterr"r�r�r�r\r
r�rqr��poprxr�rbr@)r1rr;rUr�r��my_block�
else_exitsr3r3r4�_handle__Fors 

�zAstArcAnalyzer._handle__ForcCsL|�|j�}t|dd�}|j|j|d�}t|dd�}||j|j|d�O}|S)N�-the condition on line {lineno} was never truer�r��.the condition on line {lineno} was never false)rrnr�r\r
rb)r1rr;rUr�r3r3r4�_handle__If-szAstArcAnalyzer._handle__If)�r+�	ast.Matchc
Cs�|�|�}|}t�}d}|jD]=}|�|j�}|j}t|tj�r+|jd}t|tj�s t|tj�r3d}|�	||d�t
|dd�}	||j|j|	d�O}|}q|sT|�
|	�|S)NFr�Tz+the pattern on line {lineno} always matchedz*the pattern on line {lineno} never matchedr�r�)rr&�cases�patternrxr�MatchOr�patterns�MatchAsr�r�r\r
r@)
r1rr;�
last_startr��had_wildcard�case�
case_startr�rUr3r3r4�_handle__Match6s,


��
zAstArcAnalyzer._handle__MatchcCs"|�|�}|j|jt|�d�}|S)Nr�)rr\r
r��r1rr;r�r3r3r4�_handle__NodeListMs
z AstArcAnalyzer._handle__NodeList�	ast.RaisecCr)Nz*the raise on line {lineno} wasn't executedr�)rr�r�r&)r1rr��raise_startr3r3r4�_handle__RaiseR�
zAstArcAnalyzer._handle__Raise�
ast.ReturncCr)Nz+the return on line {lineno} wasn't executedr�)rr�r�r&)r1rr��return_startr3r3r4�_handle__ReturnYr�zAstArcAnalyzer._handle__Return�ast.TrycCs�|jr|�|jd�}nd}|jr|�|jd�}nd}|dus&|dus&J�t||�}|j�|�|�|�}|j|jt|�d�}|jrNd|_	|jrMt
�|_n|j��t
�}|jr�d}|jD]%}	|�|	�}|duro|�
||�|}d}
t||
d�}||j|	j|d�O}q^|jr�|j|j|d�}||O}|j�rh|j��||jB|jB|jB|jB}|j|j|d�}
|jr�tjjr�|jD]}|j}|jj|d�}|
D]
}|�
|j||�q�q�|j}n|�|j|
�}|�|�|j�rtjj�r|jD]}|j}|jj|d�}|
D]}|�
|j||��qq�|j}n|�|j|
�}|�|�|j�r+|�|�|j|
��|j�rctjj�rW|jD]}|j}|jj|d�}|
D]}|�
|j||��qE�q7|j}n|�|j|
�}|�|�|�rh|
}|S)Nrr�z3the exception caught by line {lineno} didn't happenr�)rWr�)�handlersr�	finalbodyr�r"r�r\r
r�r�r&r�r�r�rbr�r�r�rr[�finally_jumps_backrqr�r��_combine_finally_startsr�r�r�r�)r1rr�r��	try_blockr;r��
handler_exits�last_handler_start�handler_node�
from_causerU�
final_from�final_exits�
break_linerqr��
final_exit�breaks�
continue_line�	continues�return_line�returnsr3r3r4�_handle__Try`s�

�



�����
�


�
�

�
zAstArcAnalyzer._handle__Tryr�csRg}t|�D]}|jdur|�|jj|jd��qd�|���fdd�|D�}|S)aHelper for building the cause of `finally` branches.

        "finally" clauses might not execute their exits, and the causes could
        be due to a failure to execute any of the exits in the try block. So
        we use the causes from `starts` as the causes for `exits`.
        Nr�r�csh|]}t|j���qSr3)r�rq)rwr�r�r3r4ry�rz9AstArcAnalyzer._combine_finally_starts.<locals>.<setcomp>)�sortedr�r�r�rqr�)r1r�r��causesr;r3r�r4r��s
�
z&AstArcAnalyzer._combine_finally_startscCs�|�|j�}}|�|j�}d}|rd}tjjrd}|r$|�|jd�}|j�t	|d��t
|dd�}|j|j|d�}|D]}|�|j
||j�q=t�}|j��}	t|	t	�sXJ�|�|	j�t
|dd�}|jru|j|j|d�}
||
O}|S|s||�|�|S)	NFTrr:r�r�r�r�)rrnryrr[�keep_constant_testr
r"r�r�r�r\r�rqr�r&r�rxrTr�rbr@)r1rr;�to_top�
constant_test�top_is_body0rUr�r�r�r�r3r3r4�_handle__While�s4
�
zAstArcAnalyzer._handle__While�ast.WithcCs�|�|�}tjjr|j�t|d��|j|jt	|�d�}tjjrh|j�
�}t|t�s,J�t	|�h}|rA|D]	}|�|j
|�q5|}|jrN|�|�|j|��|jr[|�|�|j|��|jrh|�|�|j|��|S)Nr:r�)rrr[rr"r�rr\r
r�r�rxr�rqr�r�r�r�r�r�r�)r1rr;r��
with_block�	with_exitr�r3r3r4�
_handle__With�s2


���zAstArcAnalyzer._handle__WithcCsj|�|�}|jr%|j|jt|�d�}|D]
}|�|j||jd�qdS|�||�|�||�dS)Nr�zdidn't exit the module)rr
r\r�r�rqr��r1rr;r�r�r3r3r4�_code_object__Modules
�z#AstArcAnalyzer._code_object__ModulecCsN|�|�}|j�t||jd��|j|jt|�d�}|�|�|j�	�dS)Nr�r�)
rr"r�r�r�r\r
r�r�r�r�r3r3r4�_code_object__FunctionDef(s


z(AstArcAnalyzer._code_object__FunctionDef�ast.ClassDefcCsX|�|�}|�||�|j|jt|�d�}|D]}|�|j||jd|j���qdS)Nr�zdidn't exit the body of class )rr�r\r
r�rqr�r�r�r3r3r4�_code_object__ClassDef1s

��z%AstArcAnalyzer._code_object__ClassDef�lambdazgenerator expressionzdictionary comprehensionzset comprehensionzlist comprehension)rr7r'r8rrrrr�r�r�)rr-)rrrr)rr4rr)rr7rr)rr;rr)rr?rr)rrBrr)rrrr�)r
rrUrVrWrrr�)rrrr])rrarr])rr	rr])rrjrr])rrrr)r�r�rr)rr~rr�)rr4rr�)rr�rr�)rr�rr�)rrarr�)rr�rr�)rr	rr�)rr�rr�)rr�rr�)rr�rr�)r�r�r�r�rr�)rrjrr�)rr�rr�)rrBrr)rr4rr)rr�rr)>r�r�r�r�r5r�r�r/rr6r:�_line__ClassDefr>�_line__FunctionDef�_line__AsyncFunctionDefrArDrRrTr\rXrdrirrryr�r�r�r�r�r��_handle__ClassDefr�r��_handle__AsyncFor�_handle__FunctionDef�_handle__AsyncFunctionDefr��sys�version_infor�r�r�r�r�r�r�r��_handle__AsyncWithr�r��_code_object__AsyncFunctionDefr�r�_code_object__Lambda�_code_object__GeneratorExprr[�comprehensions_are_functions�_code_object__DictComp�_code_object__SetComp�_code_object__ListCompr3r3r3r4r��sz

"�








$�
!
"


















o





�r��ctxr8rr�cCs,|dgdit�t�tfvpt|ttttf�S)z:Is `value` simple enough to be displayed on a single line?Nr3)r&�	frozenset�Ellipsisrx�bytesr��floatr7)r8r3r3r4�_is_simple_valueGs�r�rr�depthr�rL�Callable[[str], None]rc
Cs�d|}t|dd�}|dur=d|j�d|j��}t|d�r<t|d�s$J�|d7}|j|jkr6||j�d�7}||j�7}nd	}|�d
|jj�|��}dd�t�	|�D�}|s_||�d
��dSt
|�dkr�t|dd�r�|d\}}	||�d|�d|	�d
��dS||�	|d}
|D]V\}}	|
�|�d�}t|	�r�||�d|	���q�t|	t�r�||�d��|	D]}t|�r�||
�d|���q�t||d|d�q�||
�d��q�||�t|	|d|d�q�||�d
��dS)z`Dump the AST for `node`.

    This recursively walks the AST, printing a readable version.

    r�rqNz @ �,�
end_lineno�end_col_offsetrH��<cSs g|]\}}|tvr||f�qSr3)�SKIP_DUMP_FIELDS)rwr�r8r3r3r4�
<listcomp>fs
�zast_dump.<locals>.<listcomp>�>r9rz: z{}# mro: {}r*css�|]}|jVqdSr�)r�r�r3r3r4r�ts�zast_dump.<locals>.<genexpr>z    z [�)rL�])r'rq�
col_offsetr�r�r�r�r�r�iter_fieldsrer�r�r��__mro__rxr!r )
rr�rLr^rq�linemark�head�named_fields�
field_namer8�next_indent�prefix�nr3r3r4r NsL

��
r )r
r7rr)r8rrr�)rrr�r�rLr�rr)=r��
__future__rrr�rr<r�rJrM�typesr�typingrrrrrr	r
rrr
r�coverager�coverage.bytecoder�coverage.debugr�coverage.exceptionsrr�
coverage.miscrr�coverage.phystokensr�coverage.typesrrrrY�
namedtupler�r�r7�
TArcFragmentsr�r�r�r�rr1r	rr�r�r�rLr r3r3r3r4�<module>sV4YM +*
	3
	�