
    V.j3                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZmZ ddlmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZ ddl m!Z! ddl"m#Z#m$Z$  ee      Z G d d      Z% edd       G d d             Z& G d de      Z'e(e#e)e*ee+   ee+   f      f   Z, G d d      Z- G d de-      Z. G d de-      Z/ G d de-      Z0d!dZ1 G d d       Z2y)"zCode parsing for coverage.py.    )annotationsN)CallableIterableSequence)	dataclass)OptionalProtocolcast)env)
ByteParser)short_stack)NoSource	NotPython)isolate_module	nice_pair)generate_tokens)TArcTLineNoc                      e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 ddZddZddZ ej                  d      dd       Z	dd	Z
dd
ZddZddZddZddZddZej                  dd       ZddZddZddZy) PythonParserzParse code to find executable lines, excluded lines, etc.

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

    Nc                   |s	|sJ d       |xs d| _         ||| _        nddlm} 	  || j                         | _        || _        d| _        t               | _	        t               | _
        t               | _        t               | _        t               | _        d| _        i | _        d| _        d| _        i | _        y# t        $ r!}t        d| j                    d|       |d}~ww xY w)	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_sourcezNo source for code: 'z': F)filenametextcoverage.pythonr   OSErrorr   exclude	_ast_rootset
statementsexcludedraw_statementsraw_excludedraw_docstringsshow_tokensmultiline_map	_all_arcs_missing_arc_fragments_with_jump_fixers)selfr   r   r   r   errs         QC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\coverage/parser.py__init__zPythonParser.__init__&   s     xM!MM ,H!DI9Y-dmm<	  *.
 ), '*e -0E +.% -0E ! 68 ,0<@#@BQ  Y!6t}}oSNOUXXYs   B< <	C&C!!C&c           	         t               }d}d}t        j                  | j                  t        j                        D ]  }|j                         \  }}| j                  j                  d||      z   }| j                  j                  d||      z   }	|j                   fdt        |dz   |	dz         D               |}|} |S )zFind the lines matching a regex.

        Returns a set of line numbers, the lines that contain a match for
        `regex`. The entire line needn't match, just a part of it.
        Handles multiline regex patterns.

        r   )flags
c              3  V   K   | ]   }j                   j                  ||       " y wNr&   get).0ir*   s     r,   	<genexpr>z.PythonParser.lines_matching.<locals>.<genexpr>u   s)      6Y""&&q!,6Ys   &)      )	r   refinditerr   	MULTILINEspancountupdaterange)
r*   regexmatches
last_startlast_start_linematchstartend
start_lineend_lines
   `         r,   lines_matchingzPythonParser.lines_matchinge   s     !$
[[		FEJE3(499??4U+SSJ&z3)OOHNN 6;JNHWXL6Y  J(O G     c           
     J	   | j                   r:| j                  | j                         | _        t        | j                        | _        d}d}d}d}d}d}| j
                  J t        | j
                        }|D ]  \  }}	\  }
}\  }}}| j                  rBt        t        j                  j                  ||      ddt        |
|f      dd|	dd|       |t        j                  k(  r|d	z  }n|t        j                  k(  r|d	z  }n|t        j                   k(  rj|	d
k(  rQ|dk(  rL| j                  j#                  t%        ||d	z               }|su|rs| j                  j'                  |       |}d}nS|	dv r|d	z  }nI|	dv rE|d	z  }n?|t        j(                  k(  r,|r(||k7  r#t%        ||d	z         D ]  }|| j*                  |<    d}|	j-                         s^|t        j.                  k7  ssd}|ry|
}|r||k  rd}|s| j                  j'                  |        |sJt1        | j
                  | j2                        }| j4                  j7                  |j9                                | j;                  | j                        | _        | j<                  J t?        j@                  | j<                        D ]  }tC        |t>        jD                  t>        jF                  t>        jH                  t>        jJ                  f      r|jL                  r|jL                  d   }tC        |t>        jN                        rtC        |jP                  t>        jR                        rntC        |jP                  jP                  tT              rJ| jV                  j7                  t%        |jX                  t[        t\        |j^                        d	z                tC        |t>        jD                  t>        jF                  t>        jH                  f      sNta        d |jb                  D        |jX                        }| j                  j#                  t%        ||jX                  d	z               s| j                  j7                  t%        |t[        t\        |j^                        d	z                 y)zwParse the source to find the interesting facts about its lines.

        A handful of attributes are updated.

        r   FTNz>10 z>520r8   :z([{z)]})r   r   c              3  4   K   | ]  }|j                     y wr2   lineno)r5   ds     r,   r7   z*PythonParser._raw_parse.<locals>.<genexpr>   s     !H4Gq!((4Gs   )default)2r   rJ   r#   r   r!   r   r   r%   printtokenizetok_namer4   r   tokenINDENTDEDENTOPintersectionr@   addNEWLINEr&   stripCOMMENTr   r   r"   r?   find_statementsfirst_linesr   astwalk
isinstanceClassDefFunctionDefAsyncFunctionDefModulebodyExprvalueConstantstrr$   rR   r
   int
end_linenomindecorator_list)r*   indentexclude_indent	excluding
first_lineemptynestingtokgentoktypettextslineno_elinenoltextshould_excludelbyte_parsernodefirsts                      r,   
_raw_parsezPythonParser._raw_parse|   s    << $ 3 3DLL AD 1 12DM 	
yy$$$ +AG=GULWa,7A !))--gw?!7G"45 %,,&!ELL(!EHH$C<GqL%)]]%?%?jRY\]R]@^%_N$ ))'2)/$(	e^qLGe^qLGEMM)'Z"7 #:w{;0:**1- <
{{}H,<,<!<!!(J V~%=$)	 ))'2a BHf $$))dmmLK&&{'B'B'DE((7 ~~)))HHT^^,D$s@T@TVYV`V` ab99 IIaLE"5#((3&u{{CLLA&u{{'8'8#>++22!%,,S%:J:J0Ka0OP
 $s@T@T UV !HD4G4G!HRVR]R]^
==--eJa.PQMM((z4T__;UXY;Y)Z[% -rK   i  )maxsizec                    |dk  r!| j                   j                  | |        }|S | j                   j                  ||      }|S )zAReturn the first line number of the statement including `lineno`.r   r3   )r*   rR   s     r,   rv   zPythonParser.first_line   sP     A:((,,fWvg>>F  ''++FF;FrK   c                J    |D ch c]  }| j                  |       c}S c c}w )zMap the line numbers in `linenos` to the correct first line of the
        statement.

        Returns a set of the first lines.

        )rv   )r*   linenosr   s      r,   rb   zPythonParser.first_lines   s%     -44Gq"G444s    c                $    | j                  |      S )z)Implement `FileReporter.translate_lines`.)rb   )r*   liness     r,   translate_lineszPythonParser.translate_lines   s    &&rK   c                    | j                  |      D ch c]'  \  }}| j                  |      | j                  |      f) c}}S c c}}w )z(Implement `FileReporter.translate_arcs`.)fix_with_jumpsrv   )r*   arcsabs       r,   translate_arcszPythonParser.translate_arcs   sC    GKGZGZ[_G`aG`Va#T__Q%78G`aaas   ,Ac                   	 t        j                  | j                        | _        | j	                          | j                  | j                  z  }| j                   |z
  }| j#                  |      |z
  | _        y# t
        j                  t        t        f$ r_}t        |d      r|j                  }n|j                  d   d   }t        d| j                   d|j                  d   d| z         |d}~ww xY w)zParse source text to find executable lines, excluded lines, etc.

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

        rR   r8   r   zCouldn't parse 'z' as Python source: z	 at line N)rc   parser   r   r   rV   
TokenErrorIndentationErrorSyntaxErrorhasattrrR   argsr   r   r!   r$   r"   rb   r    )r*   r+   rR   ignorestartss        r,   parse_sourcezPythonParser.parse_source   s    	 YYtyy1DNOO !4!44$$v-**62V; ##%5{C 	sH%!Q"4==/1EFXXa[O9VH56 	s   4A8 8C5AC00C5c                n    | j                   | j                          | j                   J | j                   S )zGet 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.

        )r'   _analyze_astr*   s    r,   r   zPythonParser.arcs  s4     >>!~~)))~~rK   c                   | j                   J t        | j                  | j                   | j                  | j                        }|j                          |j                  }|j                         | _        | j                  r| j                  |      }t               | _        |D ]J  \  }}| j                  |      }| j                  |      }||k7  s.| j                  j                  ||f       L |j                  | _        y)zkRun the AstArcAnalyzer and save its results.

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

        N)r   AstArcAnalyzerr   r"   r&   analyzer   with_jump_fixersr)   r   r   r'   rv   r]   missing_arc_fragmentsr(   )r*   aaar   l1l2fl1fl2s          r,   r   zPythonParser._analyze_ast$  s     ~~)))T]]DNND<O<OQUQcQcdxx!$!5!5!7!!&&t,DFB//"%C//"%Ccz""C:.	  '*&?&?#rK   c                   t               }t               }|D ]  }|| j                  v s|d   }|j                  |       | j                  |   \  }}|| j                  v rC|j                  |       | j                  |   \  }}|j                  |       || j                  v rC|j                  ||d   f       |j                  |        t        |      |z  |z
  }|S )a  Adjust arcs to fix jumps leaving `with` statements.

        Consider this code:

            with open("/tmp/test", "w") as f1:
                a = 2
                b = 3
            print(4)

        In 3.10+, we get traces for lines 1, 2, 3, 1, 4.  But we want to present
        it to the user as if it had been 1, 2, 3, 4.  The arc 3->1 should be
        replaced with 3->4, and 1->4 should be removed.

        For this code, the fixers dict is {(3, 1): ((1, 4), (3, 4))}.  The key
        is the actual measured arc from the end of the with block back to the
        start of the with-statement.  The values are start_next (the with
        statement to the next statement after the with), and end_next (the end
        of the with-statement to the next statement after the with).

        With nested with-statements, we have to trace through a few levels to
        correct a longer chain of arcs.

        r   r8   )r   r)   r]   )r*   r   	to_removeto_addarcend0
start_nextend_nexts           r,   r   zPythonParser.fix_with_jumps;  s    0 E	Cd,,,1vc"'+'='=c'B$
H D$:$::MM*-+/+A+A*+M(JMM(+ !D$:$:: 

D(1+./j)  D	F"i/rK   c                    t        j                  t              }| j                         D ]L  \  }}|dkD  sJ d|d| j                          || j
                  v r1|| j
                  v r@||xx   dz  cc<   N |S )zYGet a count of exits from that each line.

        Excluded lines are excluded.

        r   zl1=z  should be greater than zero in r8   )collectionsdefaultdictro   r   r   r!   )r*   exit_countsr   r   s       r,   r   zPythonParser.exit_countsc  s     +6*A*A#*FiikFB6RcbU"B4==/RR6T]]"T]]"Oq O " rK   c                B    |
|dk  rd}nd}|j                  |      }|S )z=Apply some defaulting and formatting to an arc's description.r   zjump to the function exitzjump to line {lineno}rQ   )format)r*   
action_msgrG   s      r,   _finish_action_msgzPythonParser._finish_action_msgw  s2    Qw8
4
&&c&2
rK   c                X   | j                   | j                          | j                   J | j                   j                  ||fdg      }g }|D ]J  \  }}| j                  ||      }d| d| }||d|j	                  |       z  }|j                  |       L dj                  |      S )z5Provide an English sentence describing a missing arc.NNzline z didn't z	 because rQ   z or )r(   r   r4   r   r   appendjoin)r*   rF   rG   fragment_pairsmsgsmissing_cause_msgr   msgs           r,   missing_arc_descriptionz$PythonParser.missing_arc_description  s    &&...:::4488%~V-;)z00SAJ%5C ,#4#;#;5#;#I"JKKKK .< {{4  rK   c                    | j                   | j                          | j                   J | j                   j                  ||fdg      }| j                  |d   d   |      }|S )z2Provide an English description of an arc's effect.r   r   r8   )r(   r   r4   r   )r*   rF   rG   r   r   s        r,   arc_descriptionzPythonParser.arc_description  sl    &&...:::4488%~V,,^A->q-A3G
rK   )NNN)r   
str | Noner   r   r   r   returnNone)rA   rn   r   set[TLineNo]r   r   )rR   r   r   r   )r   Iterable[TLineNo]r   r   )r   r   r   r   )r   zIterable[TArc]r   	set[TArc])r   r   )r   zdict[TLineNo, int])r   r   rG   r   r   rn   )rF   r   rG   r   r   rn   )__name__
__module____qualname____doc__r-   rJ   r   	functools	lru_cacherv   rb   r   r   r   r   r   r   r   r   r   r    rK   r,   r   r      s      #"	=C=C =C 	=C
 
=C~.h\T Y& '5'b<0
@.&P  &!&rK   r   T)frozenorderc                  *    e Zd ZU dZded<   dZded<   y)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 `missing_cause_msg` 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.

    As an example, this code::

        if something(x):        # line 1
            func(x)             # line 2
        more_stuff()            # line 3

    would have two ArcStarts:

    - ArcStart(1, "the condition on line 1 was always true")
    - ArcStart(1, "the condition on line 1 was never true")

    The first would be used to create an arc from 1 to 3, creating a message like
    "line 1 didn't jump to line 3 because the condition on line 1 was always true."

    The second would be used for the arc from 1 to 2, creating a message like
    "line 1 didn't jump to line 2 because the condition on line 1 was never true."

    r   rR    rn   causeN)r   r   r   r   __annotations__r   r   rK   r,   r   r     s    : OE3OrK   r   c                  0    e Zd ZdZ	 	 d	 	 	 	 	 	 	 	 	 ddZy)	TAddArcFnz&The type for AstArcAnalyzer.add_arc().Nc                     y)ab  
        Record an arc from `start` to `end`.

        `missing_cause_msg` is a description of the reason the arc wasn't
        taken if it wasn't taken.  For example, "the condition on line 10 was
        never true."

        `action_msg` is a description of what the arc does, like "jump to line
        10" or "exit from function 'fooey'."

        Nr   r*   rF   rG   r   r   s        r,   __call__zTAddArcFn.__call__  s    rK   r   
rF   r   rG   r   r   r   r   r   r   r   )r   r   r   r   r   r   rK   r,   r   r     sB    0 )-!%  &	
  
rK   r   c                  0    e Zd ZdZddZddZddZddZy)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.
    c                     y)zProcess break exits.Fr   r*   exitsadd_arcs      r,   process_break_exitszBlock.process_break_exits      rK   c                     y)zProcess continue exits.Fr   r   s      r,   process_continue_exitszBlock.process_continue_exits  r   rK   c                     y)zProcess raise exits.Fr   r   s      r,   process_raise_exitszBlock.process_raise_exits  r   rK   c                     y)zProcess return exits.Fr   r   s      r,   process_return_exitszBlock.process_return_exits  r   rK   Nr   set[ArcStart]r   r   r   bool)r   r   r   r   r   r   r   r   r   rK   r,   r   r     s    rK   r   c                  (    e Zd ZdZddZddZddZy)	LoopBlockz@A block on the block stack representing a `for` or `while` loop.c                0    || _         t               | _        y r2   )rF   r   break_exits)r*   rF   s     r,   r-   zLoopBlock.__init__   s    
*-%rK   c                :    | j                   j                  |       yNT)r   r?   r   s      r,   r   zLoopBlock.process_break_exits  s    &rK   c                b    |D ]*  } ||j                   | j                  |j                         , yr   )rR   rF   r   r*   r   r   xits       r,   r   z LoopBlock.process_continue_exits
  s'    CCJJ

CII6 rK   N)rF   r   r   r   r   )r   r   r   r   r-   r   r   r   rK   r,   r   r     s    J0rK   r   c                  (    e Zd ZdZddZddZddZy)FunctionBlockz>A block on the block stack representing a function definition.c                     || _         || _        y r2   rF   name)r*   rF   r   s      r,   r-   zFunctionBlock.__init__  s    
	rK   c                    |D ]9  } ||j                   | j                   |j                  d| j                         ; y)Nzexcept from function TrR   rF   r   r   r   s       r,   r   z!FunctionBlock.process_raise_exits  >    C

		'		}5	  rK   c                    |D ]9  } ||j                   | j                   |j                  d| j                         ; y)Nzreturn from function Tr   r   s       r,   r   z"FunctionBlock.process_return_exits#  r   rK   N)rF   r   r   rn   r   r   r   )r   r   r   r   r-   r   r   r   rK   r,   r   r     s    HrK   r   c                       e Zd ZdZddZddZy)TryBlockz6A block on the block stack representing a `try` block.c                     || _         || _        y r2   )handler_startfinal_start)r*   r  r  s      r,   r-   zTryBlock.__init__1  s    *&rK   c                z    | j                   /|D ]*  } ||j                  | j                   |j                         , yr   )r  rR   r   r   s       r,   r   zTryBlock.process_raise_exits7  s5    )

D$6$6		B rK   N)r  TLineNo | Noner  r  r   r   r   )r   r   r   r   r-   r   r   rK   r,   r  r  .  s    @'rK   r  c                   | xt         j                  d x\    dt        | j                        fS  xt         j                  d x)\    | j
                  dv rdt        | j
                        fS y xt         j                  d xE\    t        | j                  t         j                        rt        | j                        \  }}|| fS y t         j                  d xz\   | j                  D cg c]  }t        |       }}t        d |D              }|rAt        | j                  t         j                         rt"        nt        }d |d |D              fS y yc c}w )zIs this a compile-time constant test expression?

    We don't try to mimic all of CPython's optimizations.  We just have to
    handle the kinds of constant expressions people might actually use.

    r   T)TrueFalser   	__debug__c              3  &   K   | ]	  \  }}|  y wr2   r   )r5   is_constr}   s      r,   r7   z(is_constant_test_expr.<locals>.<genexpr>T  s     ?$;8Qh$   c              3  &   K   | ]	  \  }}|  y wr2   r   )r5   r}   vs      r,   r7   z(is_constant_test_expr.<locals>.<genexpr>W  s     3ddadr  )FF)rc   rm   r   rl   NameidevalUnaryOpre   opNotis_constant_test_exproperandBoolOpvaluesallOrany)r   is_constantvalr  retsr  s         r,   r  r  A  s&    S\\^djj))) SXXZww@@T$'']**   S[[]$''377+#8#F S"G++   ZZ\6:kkBk)!,kDB?$??K&tww7SSR3d3333   Cs   ,Ec                  x   e Zd ZdZ	 	 	 	 	 	 	 	 	 	 d#dZd$dZd%dZd&dZd'dZeZ	d(dZ
	 	 d)	 	 	 	 	 	 	 	 	 d*d	Zd+d
Zd,dZd-dZd.dZeZd/dZeZeZd0dZd1dZh dZd2dZ	 	 d)	 	 	 	 	 	 	 d3dZd4dZd4dZd4dZd4dZd5dZd6dZeZd7dZ d8dZ!e!Z"eZ#eZ$d9dZ%d:dZ&d;dZ'd<dZ(d=d Z)e)Z*d>d!Z+d?d"Z,e,Z-y)@r   a  Analyze source text with an AST to find executable code paths.

    The .analyze() method does the work, and populates these attributes:

    `arcs`: a set of (from, to) pairs of the the arcs possible in the code.

    `missing_arc_fragments`: a dict mapping (from, to) arcs to lists of
    message fragments explaining why the arc is missing from execution::

        { (start, end): [(missing_cause_msg, action_msg), ...], }

    For an arc starting from line 17, they should be usable to form complete
    sentences like: "Line 17 didn't {action_msg} because {missing_cause_msg}".

    NOTE: Starting in July 2024, I've been whittling this down to only report
    arc that are part of true branches.  It's not clear how far this work will
    go.

    c                   || _         || _        |D ch c]  }|j                  ||       c}| _        || _        t        t        t        j                  dd                  }|r[t        d| j                          t        d| j                          t        t        j                  | j                  dd             t               | _        t        j                  t               | _        g | _        t               | _        t               | _        t               | _        t               | _        t        t        t        j                  dd                  | _        y c c}w )	NCOVERAGE_AST_DUMP0zStatements: zMultiline map: T   )include_attributesrs   COVERAGE_TRACK_ARCS)r   	root_noder4   r    	multiliner   ro   osgetenvrU   rc   dumpr   r   r   r   listr   block_stackcurrent_with_startsall_with_startswith_entries
with_exitsdebug)r*   r   r)  r    r*  r   dump_asts          r,   r-   zAstArcAnalyzer.__init__p  s    !"8BC
19==A.
C" BII&93?@AL 123ODNN#345#((4>>d1MN"u	4?4K4KD4Q"(* 25 -0U'*u%(U #bii(=sCDE
7 Ds   Ec                    t        j                  | j                        D ]3  }|j                  j                  }t        | d| d      }|, ||       5 y)zFExamine the AST tree from `self.root_node` to determine possible arcs._code_object__N)rc   rd   r)  	__class__r   getattr)r*   r   	node_namecode_object_handlers       r,   r   zAstArcAnalyzer.analyze  sL    HHT^^,D//I")$.0Ld"S".#D)	 -rK   c                   i }| j                   D ch c]#  }|d   | j                  v r|| j                  vr|% }}| j                  D ]  }|D ch c]  }|d   |k(  s|d    }}|s!t        |      dk(  sJ d| d|       |j	                         }| j
                  D ch c]  }|d   |k(  s|d    }}|D ]  }||f||ff|||f<     |S c c}w c c}w c c}w )aK  Get a dict with data for fixing jumps out of with statements.

        Returns a dict.  The keys are arcs leaving a with-statement by jumping
        back to its start.  The values are pairs: first, the arc from the start
        to the next statement, then the arc that exits the with without going
        to the start.

        r   r8   zExpected one arc, got z with start = )r   r1  r2  lenpopr3  )	r*   fixersr   
with_nextsrF   nextsnxtendsrG   s	            r,   r   zAstArcAnalyzer.with_jump_fixers  s     yy
 1v---#T=N=N2N   	 

 ))E'1EzSVu_SVzEEu:?T&<UG?%$TT?))+C&*ooIosQ5CFoDI).sCj'AU|$  * 
 F
 Js   (CCC!C/Cc                    | j                  |      }|j                  rL| j                  |j                        }|D ]+  }| j                  |j                  | |j
                  d       - y | j                  ||        y )Nzexit the module)line_for_noderj   process_bodyr   rR   r   r*   r   rF   r   r   s        r,   _code_object__Modulez#AstArcAnalyzer._code_object__Module  sf    ""4(99%%dii0ESZZ%<MN  LL'rK   c                   | j                  |      }| j                  j                  t        ||j                               | j                  |j                        }| j                  |       | j                  j                          y )Nr   )	rE  r/  r   r   r   rF  rj   r   r>  )r*   r   rF   r   s       r,   _code_object__FunctionDefz(AstArcAnalyzer._code_object__FunctionDef  se    ""4(E		 JK!!$)),!!%(rK   c                    | j                  |      }| j                  |j                        }|D ]8  }| j                  |j                  | |j
                  d|j                         : y )Nzexit class )rE  rF  rj   r   rR   r   r   rG  s        r,   _code_object__ClassDefz%AstArcAnalyzer._code_object__ClassDef  sW    ""4(!!$)),CLLeVSYY+dii]8ST rK   Nc           
     R   | j                   r,t        d| d| d|d|       t        t               d       | j                  j	                  ||f       || j
                  v r| j                  j	                  ||f       ||#| j                  ||f   j                  ||f       yy)z@Add an arc, including message fragments to use if it is missing.zAdding possible arc: (z, z): z

)rG   N)	r4  rU   r   r   r]   r0  r2  r   r   r   s        r,   r   zAstArcAnalyzer.add_arc  s     ::*5'C5<M;PPRS]R`ab+-V,		ucl#D,,,!!5#,/(J,B&&s|4;;=NPZ<[\ -CrK   c                ,    t        | j                        S )z.Yield the blocks in nearest-to-farthest order.)reversedr/  r   s    r,   nearest_blockszAstArcAnalyzer.nearest_blocks  s    (())rK   c                   |j                   j                  }t        t        t        t
        j                  gt        f      t        | d| d            }|	 ||      }n|j                  }| j                  j                  ||      S )z}What is the right line number to use for this node?

        This dispatches to _line__Node functions where needed.

        _line__N)r8  r   r
   r   r   rc   ASTr   r9  rR   r*  r4   )r*   r   r:  handlerlines        r,   rE  zAstArcAnalyzer.line_for_node  sy     NN++	Xswwi012DGI;/6
 4=D;;D~~!!$--rK   c                l    |j                   r|j                   d   j                  }|S |j                  }|S )zSCompute first line number for things that can be decorated (classes and functions).r   )rr   rR   )r*   r   rR   s      r,   _line_decoratedzAstArcAnalyzer._line_decorated  s8    ((+22F  [[FrK   c                8    | j                  |j                        S r2   )rE  rl   r*   r   s     r,   _line__AssignzAstArcAnalyzer._line__Assign
  s    !!$**--rK   c                    |j                   rA|j                   d   |j                   d   j                  S |j                  d   j                  S |j                  S Nr   )keysrR   r  rY  s     r,   _line__DictzAstArcAnalyzer._line__Dict  sK    99yy|'yy|*** {{1~,,,;;rK   c                n    |j                   r| j                  |j                   d         S |j                  S r\  )eltsrE  rR   rY  s     r,   _line__ListzAstArcAnalyzer._line__List  s,    99%%diil33;;rK   c                     y)Nr8   r   rY  s     r,   _line__ModulezAstArcAnalyzer._line__Module#  s    rK   >   rk   PassAssertAssignDeleteGlobalImportNonlocal	AnnAssign	AugAssign
ImportFromc                `   |j                   j                  }t        t        t        t
        j                  gt        t           f      t        | d| d            }|
 ||      }|S t        j                  r|| j                  vrt        d|       t        | j                  |            h}|S )a  Find the set of arc starts that exit this 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 three exits from line 1: they start at lines 1, 3 and 5.
        There are two exits from line 2: lines 3 and 5.

        	_handle__Nz*** Unhandled: )r8  r   r
   r   r   rc   rS  r   r   r9  r   TESTINGOK_TO_DEFAULTRuntimeErrorrE  )r*   r   r:  rT  
arc_startss        r,   
node_exitszAstArcAnalyzer.node_exits5  s    " NN++	XswwiX678DIi[148
  J  {{D$6$66&'?@@ #4#5#5d#;<=JrK   c                    ||t               }n|h}n|J |D ]a  }| j                  |      }|| j                  vr#|D ])  }| j                  |j                  ||j
                         + | j                  |      }c |S )a  Process the body of a compound statement.

        `body` is the body node to process.

        `from_start` is a single `ArcStart` that starts an arc into this body.
        `prev_starts` is a set of ArcStarts that can all be the start of arcs
        into this body.  Only one of `from_start` and `prev_starts` should be
        given.

        Records arcs within the body by calling `self.add_arc`.

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

        )r   rE  r    r   rR   r   rt  )r*   rj   
from_startprev_starts	body_noderR   
prev_starts          r,   rF  zAstArcAnalyzer.process_bodyX  s    ( !!e)l%%% I''	2FT__,)
Z..
8H8HI *//)4K  rK   c                j    | j                         D ]   }|j                  || j                        s  y y)z0Add arcs due to jumps from `exits` being breaks.N)rP  r   r   r*   r   blocks      r,   r   z"AstArcAnalyzer.process_break_exits  ,    ((*E((= +rK   c                j    | j                         D ]   }|j                  || j                        s  y y)z3Add arcs due to jumps from `exits` being continues.N)rP  r   r   r{  s      r,   r   z%AstArcAnalyzer.process_continue_exits  s,    ((*E++E4<<@ +rK   c                j    | j                         D ]   }|j                  || j                        s  y y)z0Add arcs due to jumps from `exits` being raises.N)rP  r   r   r{  s      r,   r   z"AstArcAnalyzer.process_raise_exits  r}  rK   c                j    | j                         D ]   }|j                  || j                        s  y y)z1Add arcs due to jumps from `exits` being returns.N)rP  r   r   r{  s      r,   r   z#AstArcAnalyzer.process_return_exits  s,    ((*E))%> +rK   c                v    | j                  |      }t        |d      }| j                  |h       t               S )Nz*the break on line {lineno} wasn't executedr   )rE  r   r   r   )r*   r   herebreak_starts       r,   _handle__BreakzAstArcAnalyzer._handle__Break  s6    !!$'t+WX  +/urK   c                |   |j                   }|j                   }|j                  }|rd}|D ].  }| j                  |      }|||k7  r| j                  ||       |}0 |J | j                  ||       |}|j                  s.J d|j                  d| j
                   d|j                           |J t        |      hS )zBAdd arcs for things that can be decorated (classes and functions).NzOops: node.body = z in @)rR   rr   rE  r   rj   r   r   )r*   r   	main_linelastdecsdec_node	dec_starts          r,   _handle_decoratedz AstArcAnalyzer._handle_decorated  s    ![[	#{{""D  ..x8	#	T(9LLy1 	 !
 ###LLy)D
 99V 3tyynDqVV9rK   c                v    | j                  |      }t        |d      }| j                  |h       t               S )Nz-the continue on line {lineno} wasn't executedr  )rE  r   r   r   )r*   r   r  continue_starts       r,   _handle__Continuez AstArcAnalyzer._handle__Continue  s7    !!$'!$.]^##^$45urK   c                B   | j                  |j                        }| j                  j                  t	        |             t        |d      }| j                  |j                  |      }|D ])  }| j                  |j                  ||j                         + | j                  j                         }t        |t              sJ |j                  }t        |d      }|j                  r$| j                  |j                  |      }||z  }|S |j                  |       |S )NrF   z'the loop on line {lineno} never startedr  rv  z)the loop on line {lineno} didn't complete)rE  iterr/  r   r   r   rF  rj   r   rR   r   r>  re   r   orelser]   )r*   r   rF   rv  r   r   my_block
else_exitss           r,   _handle__ForzAstArcAnalyzer._handle__For  s    ""499-	 67e+TU
!!$))
!CCLLUCII6 ##'')(I...$$e+VW
;;**4;;:*NJZE  IIj!rK   c                D   | j                  |j                        }t        |j                        \  }}t               }|r|r-t	        |d      }|| j                  |j                  |      z  }|r|s-t	        |d      }|| j                  |j                  |      z  }|S )N-the condition on line {lineno} was never truer  r  .the condition on line {lineno} was always true)rE  testr  r   r   rF  rj   r  )r*   r   rF   constant_testr   r   rv  s          r,   _handle__IfzAstArcAnalyzer._handle__If  s    ""499-2499=s!%/^_JT&&tyyZ&HHEC!%/_`JT&&t{{z&JJErK   c                   | j                  |      }|}t               }|j                  D ]_  }| j                  |j                        }| j	                  ||d       t        |d      }|| j                  |j                  |      z  }|}a j                  }t        |t        j                        r*|j                  d   }t        |t        j                        r*t        |t        j                        r?|j                  3|j                  }t        |t        j                        r|j                  3t        |t        j                        xr |j                  d u xr |j                  d u }	|	s|j                  t        d             |S )Nz+the pattern on line {lineno} always matchedz*the pattern on line {lineno} never matchedr  r  )rE  r   casespatternr   r   rF  rj   re   rc   MatchOrpatternsMatchAsguardr]   )
r*   r   rF   rC   r   case
case_startrv  r  had_wildcards
             r,   _handle__MatchzAstArcAnalyzer._handle__Match  sM   ""4(
JJD++DLL9JLLZ1^_!BJ T&&tyyZ&HHE#J  ,,#++.&&r*G #++.#++.7??3NooG #++.7??3N w,_D1H_TZZ[_M_ 	 II+XY rK   c                v    | j                  |      }t        |d      }| j                  |h       t               S )Nz*the raise on line {lineno} wasn't executedr  )rE  r   r   r   )r*   r   r  raise_starts       r,   _handle__RaisezAstArcAnalyzer._handle__Raise  s6    !!$'t+WX  +/urK   c                v    | j                  |      }t        |d      }| j                  |h       t               S )Nz+the return on line {lineno} wasn't executedr  )rE  r   r   r   )r*   r   r  return_starts       r,   _handle__ReturnzAstArcAnalyzer._handle__Return  s6    !!$',YZ!!<.1urK   c                   |j                   r| j                  |j                   d         }nd }|j                  r| j                  |j                  d         }nd }||J t        ||      }| j                  j                  |       | j                  |      }| j                  |j                  t        |            }|j                  rd |_	        n| j                  j                          t               }|j                   rQ|j                   D ]B  }| j                  |      }d}	t        ||	      }
|| j                  |j                  |
      z  }D |j                  r| j                  |j                  |      }||z  }|j                  r=| j                  j                          |}| j                  |j                  |      }|r|}|S )Nr   r  z3the exception caught by line {lineno} didn't happenr  )rw  )handlersrE  	finalbodyr  r/  r   rF  rj   r   r  r>  r   r  )r*   r   r  r  	try_blockrF   r   handler_exitshandler_node
from_causerv  
final_fromfinal_exitss                r,   _handle__TryzAstArcAnalyzer._handle__Try!  s   == ..t}}Q/?@M M>>,,T^^A->?KK (K,CCC]K8		*""4(!!$))!H
 >>&*I#  "'*u== $ $ 2 2< @R
%m:F
!2!2<3D3DQ[!2!\\	 !. ;;%%dkku%EE>>  "J++DNN
+SK $rK   c                   | j                  |j                        x}}t        |j                        \  }}| j                  j	                  t        |             t        |d      }| j                  |j                  |      }|D ])  }| j                  |j                  ||j                         + t               }| j                  j                         }	t        |	t
              sJ |j                  |	j                          t        |d      }|j"                  r$| j                  |j"                  |      }
||
z  }|S |s|j%                  |       |S )Nr  r  r  r  r  )rE  r  r  r/  r   r   r   rF  rj   r   rR   r   r   r>  re   r?   r   r  r]   )r*   r   rF   to_topr  r}   rv  r   r   r  r  s              r,   _handle__WhilezAstArcAnalyzer._handle__WhileZ  s    ++DII660;q	 78e+Z[
!!$))
!CCLLVSYY7 ##'')(I...X))*e+[\
;;**4;;:*NJZE
  !		*%rK   c                   t         j                  j                  r3|j                  D cg c]  }| j	                  |j
                         }}n| j	                  |      g}|D ]8  }| j                  j                  |       | j                  j                  |       : | j                  |j                  t        |d               }|d   }| j                  j                  |       t        |      h}|rL|D ]E  }| j                  |j                  |       | j                  j                  |j                  |f       G |}|S c c}w )Nr  r  )r   
PYBEHAVIORexit_with_through_ctxmgritemsrE  context_exprr0  r]   r1  rF  rj   r   remover   rR   r3  )r*   r   itemr   rF   r   	with_exitr   s           r,   _handle__WithzAstArcAnalyzer._handle__Withp  s   >>22HL

S
d(():):;
FS((./FE$$((/  $$U+  !!$))8L!Mr
  ''.e_%	SZZ/##SZZ$78  E% Ts   "E)
r   rn   r)  ast.ASTr    r   r*  zdict[TLineNo, TLineNo]r   r   r   )r   zdict[TArc, tuple[TArc, TArc]])r   
ast.Moduler   r   )r   ast.FunctionDefr   r   )r   zast.ClassDefr   r   r   r   )r   zIterable[Block])r   r  r   r   )r   r  r   r   )r   z
ast.Assignr   r   )r   zast.Dictr   r   )r   zast.Listr   r   )r   r  r   r   )r   r  r   r   )rj   zSequence[ast.AST]rv  zArcStart | Nonerw  zset[ArcStart] | Noner   r   )r   r   r   r   )r   z	ast.Breakr   r   )r   r  r   r   )r   zast.Continuer   r   )r   zast.Forr   r   )r   zast.Ifr   r   )r   z	ast.Matchr   r   )r   z	ast.Raiser   r   )r   z
ast.Returnr   r   )r   zast.Tryr   r   )r   z	ast.Whiler   r   )r   zast.Withr   r   ).r   r   r   r   r-   r   r   rH  rJ  _code_object__AsyncFunctionDefrL  r   rP  rE  rW  rZ  _line__ClassDefr^  _line__FunctionDef_line__AsyncFunctionDefra  rc  rq  rt  rF  r   r   r   r   r  r  _handle__ClassDefr  r  _handle__AsyncFor_handle__FunctionDef_handle__AsyncFunctionDefr  r  r  r  r  _handle__TryStarr  r  _handle__AsyncWithr   rK   r,   r   r   [  s   ($F$F $F !	$F
 *$F 
$FL*>( &?"U )-!%]] ] &	]
 ] 
]$*.,. &O	 )-M!L '+,0	%% $% *	%
 
%^" 0 *( %, 1
<5n $,, 'rK   r   )r   r  r   ztuple[bool, bool])3r   
__future__r   rc   r   r   r+  r:   rX   rV   collections.abcr   r   r   dataclassesr   typingr   r	   r
   coverager   coverage.bytecoder   coverage.debugr   coverage.exceptionsr   r   coverage.miscr   r   coverage.phystokensr   coverage.typesr   r   r   r   r   dictr.  tuplern   TArcFragmentsr   r   r   r  r  r   r   rK   r,   <module>r     s    $ " 
   	 	   8 8 ! + +  ( & 3 3 / (B~ ~L $d#  $D . T4hsmXc]&B CDDE 8 &E <u &4k' k'rK   