
    *e              
      \   U 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
Z
ddlmZmZ ddlmZ ddlmZmZmZ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 ddl m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z, 	 ddl-m.Z. dZ/n# e0$ r dZ/Y nw xY w ej1        e*j2        dfe*j3        dfe*j4        dfe*j5        dfe*j6        dfe*j7        dfe*j8        dfg          Z9de:d<   ee;eede;gdf         e<f         f         Z=de:d<   i Z>d e:d!<    G d" d          Z? G d# de$          Z@	 dadbd-ZAdcd0ZBddd2ZCded4ZD G d5 d6e'          ZE G d7 d8e@          ZF eAd9eF            G d: d;e@          ZG eAd<eG            G d= d>e'          ZH G d? d@e@          ZI eAdAeI            G dB dC          ZJ G dD dEe@          ZK eAdFeKdG           dfdKZL G dL dM          ZM G dN dOe@          ZN eAdPeNdG            G dQ dRe@          ZO G dS dTeO          ZP eAdUePdG            G dV dWeO          ZQ eAdXeQdG            G dY dZeO          ZR eAd[eRdG            eBdXd\            eBd[d]            G d^ d_e@          ZS eAd`eS            eTe>           eTe          k    sJ dS )gz5Classes for producing HTML reports about imprecision.    )annotationsN)ABCMetaabstractmethod)
attrgetter)AnyCallableDictFinalIteratorTuple)	TypeAlias)pathname2url)stats)REPORTER_NAMES)
ExpressionFuncDefMypyFile)Options)TraverserVisitor)Type	TypeOfAny)__version__)etreeTFUnannotatedExplicit
UnimportedzOmitted GenericsErrorzSpecial FormzImplementation Artifactz(Final[collections.OrderedDict[int, str]]type_of_any_name_mapReportsAbstractReporter
_TypeAliasReporterClasseszFinal[ReporterClasses]reporter_classesc                  .    e Zd ZddZddZddZddZdS )r   data_dirstrreport_dirsdict[str, str]returnNonec                    || _         g | _        i | _        t          |                                          D ]\  }}|                     ||           d S N)r%   	reportersnamed_reporterssorteditems
add_report)selfr%   r'   report_type
report_dirs        +lib/python3.11/site-packages/mypy/report.py__init__zReports.__init__6   sa     13<>'-k.?.?.A.A'B'B 	5 	5#KOOK4444	5 	5    r3   r4   r    c                >   	 | j         |         S # t          $ r Y nw xY wt          |         \  }}|r<t          s5t	          d                    |          t          j                   t           || |          }| j	        
                    |           || j         |<   |S )NzYou must install the lxml package before you can run mypy with `--{}-report`.
You can do this with `python3 -m pip install lxml`.)file)r.   KeyErrorr#   LXML_INSTALLEDprintformatsysstderrImportErrorr-   append)r2   r3   r4   reporter_cls
needs_lxmlreporters         r5   r1   zReports.add_report>   s    	'44 	 	 	D	#3K#@ j 		n 		J &%%Z    <j11h''',4[)s    
treer   modulesdict[str, MypyFile]type_mapdict[Expression, Type]optionsr   c                J    | j         D ]}|                    ||||           d S r,   )r-   on_file)r2   rE   rF   rH   rJ   rD   s         r5   r9   zReports.fileS   s<      	? 	?HT7Hg>>>>	? 	?r7   c                B    | j         D ]}|                                 d S r,   )r-   	on_finish)r2   rD   s     r5   finishzReports.finish]   s2     	! 	!H    	! 	!r7   N)r%   r&   r'   r(   r)   r*   )r3   r&   r4   r&   r)   r    
rE   r   rF   rG   rH   rI   rJ   r   r)   r*   r)   r*   )__name__
__module____qualname__r6   r1   r9   rO    r7   r5   r   r   5   sd        5 5 5 5   *? ? ? ?! ! ! ! ! !r7   c                  F    e Zd ZddZedd            Zedd            ZdS )r    reportsr   
output_dirr&   r)   r*   c                L    || _         |dk    rt          j        |           d S d S )N<memory>)rX   r   ensure_dir_exists)r2   rW   rX   s      r5   r6   zAbstractReporter.__init__c   s3    $###J///// $#r7   rE   r   rF   rG   rH   rI   rJ   r   c                    d S r,   rU   r2   rE   rF   rH   rJ   s        r5   rL   zAbstractReporter.on_fileh   s	     	r7   c                    d S r,   rU   r2   s    r5   rN   zAbstractReporter.on_finishr   s    r7   NrW   r   rX   r&   r)   r*   rP   rQ   )rR   rS   rT   r6   r   rL   rN   rU   r7   r5   r    r    b   sh        0 0 0 0
    ^    ^  r7   )	metaclassreport_namer&   rD   *Callable[[Reports, str], AbstractReporter]rC   boolr)   r*   c                    ||ft           | <   d S r,   r#   )rb   rD   rC   s      r5   register_reporterrg   w   s    
 &.z$:[!!!r7   source_reportertarget_reporterc                0    t           |          t           |<   d S r,   rf   )rh   ri   s     r5   alias_reporterrk      s    (8(I_%%%r7   pathc                    t          j        |           rdS |                     d          rdS d|                     d          v s!d|                     t          j                  v rdS dS )NT..stubs/F)r   is_special_module
startswithsplitossep)rl   s    r5   should_skip_pathrv      sj    t$$ tt t$**S//!!W

260B0B%B%Bt5r7   Iterator[tuple[int, str]]c              #     K   	 t          j        |           5 }t          |d          E d{V  ddd           dS # 1 swxY w Y   dS # t          $ r Y dS w xY w)zDReturn an iterator over (line number, line text) from a Python file.   N)tokenizeopen	enumerateIsADirectoryError)rl   
input_files     r5   iterate_python_linesr      s      ]4   	0J Q/////////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0   s1   A	 <A	 A  A	 A A	 	
AAc                  (     e Zd Zd fdZddZ xZS )	FuncCounterVisitorr)   r*   c                Z    t                                                       ddg| _        d S Nr   superr6   counts)r2   	__class__s    r5   r6   zFuncCounterVisitor.__init__   s(    !fr7   defnr   c                >    | j         |j        d uxx         dz  cc<   d S Nry   )r   type)r2   r   s     r5   visit_func_defz!FuncCounterVisitor.visit_func_def   s-    DIT)***a/*****r7   rQ   r   r   r)   r*   )rR   rS   rT   r6   r   __classcell__r   s   @r5   r   r      sQ             0 0 0 0 0 0 0 0r7   r   c                  0     e Zd Zd fdZddZddZ xZS )LineCountReporterrW   r   rX   r&   r)   r*   c                Z    t                                          ||           i | _        d S r,   r   r2   rW   rX   r   s      r5   r6   zLineCountReporter.__init__   s(    *---<>r7   rE   r   rF   rG   rH   rI   rJ   r   c                ~   	 t          |j        d          5 }t          |                                          }d d d            n# 1 swxY w Y   n# t          $ r d}Y nw xY wt                      }|                    |           |j        \  }}	|	|z   }
|j        rd}	|
r||	z  |
z  n|}|||	|
f| j        |j	        <   d S )Nrbr   )
r{   rl   len	readlinesr}   r   acceptr   ignore_errors	_fullname)r2   rE   rF   rH   rJ   fphysical_linesfunc_counterunannotated_funcsannotated_funcstotal_funcsimputed_annotated_liness               r5   rL   zLineCountReporter.on_file   s4   	di&& 4!!$Q[[]]!3!34 4 4 4 4 4 4 4 4 4 4 4 4 4 4  	 	 	NNN	 *++L!!!-9-@*?%(99   	 O @K^N_,;;P^ 	 
 $	'
DN###s3   A "AA A		A A	A A A c                    t          d | j                                        D             d          t          fdt	          d          D                       }t          t          j                            | j	        d          d          5 }|
                     dj        |            D ]E\  }}|
                    |d	         d
d|d         d
d|d         dd|d         dd| d
           F	 d d d            d S # 1 swxY w Y   d S )Nc              3  $   K   | ]\  }}||fV  d S r,   rU   ).0pcs      r5   	<genexpr>z.LineCountReporter.on_finish.<locals>.<genexpr>   s*      441aV444444r7   T)reversec              3  P   K   | ]t          fd D                       V   dS )c              3  .   K   | ]\  }}|         V  d S r,   rU   )r   r   r   is      r5   r   z8LineCountReporter.on_finish.<locals>.<genexpr>.<genexpr>   s+       9 9$!Q1 9 9 9 9 9 9r7   N)sum)r   r   r   s    @r5   r   z.LineCountReporter.on_finish.<locals>.<genexpr>   sA      LLaS 9 9 9 9& 9 9 999LLLLLLr7      zlinecount.txtwz{:7} {:7} {:6} {:6} total
r   7 ry      6   
)r/   r   r0   tupleranger{   rt   rl   joinrX   writer=   )r2   total_countsr   r   r   r   s        @r5   rN   zLineCountReporter.on_finish   s   >D44 1 1 3 3444d?
 ?
 ?
 LLLL588LLLLL"',,t@@#FF 	F!GG818,GHHH F F11Q4DDDAaDDDDQqTDDDadDDDqDDDEEEEF	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   A&DD
Dr`   rP   rQ   )rR   rS   rT   r6   rL   rN   r   r   s   @r5   r   r      sn        ? ? ? ? ? ?"
 "
 "
 "
HF F F F F F F Fr7   r   	linecountc                  L     e Zd ZdZd fdZddZddZddZddZddZ	 xZ
S ) AnyExpressionsReporterz3Report frequencies of different kinds of Any types.rW   r   rX   r&   r)   r*   c                h    t                                          ||           i | _        i | _        d S r,   )r   r6   r   any_types_counterr   s      r5   r6   zAnyExpressionsReporter.__init__   s2    *---24FHr7   rE   r   rF   rG   rH   rI   rJ   r   c                   t          j        d|j        ||dd          }|                    |           |j        | j        |j        <   t          |j                                                  	                    t           j
                  }|j        |z   }|j        |j        z   |z   }|dk    r||f| j        |j        <   d S d S )NTF)inferredfilenamerF   typemap	all_nodesvisit_untyped_defsr   )r   StatisticsVisitorfullnamer   type_of_any_counterr   listline_mapvaluescountTYPE_UNANALYZEDnum_any_exprsnum_imprecise_exprsnum_precise_exprsr   )	r2   rE   rF   rH   rJ   visitornum_unanalyzed_linesnum_any	num_totals	            r5   rL   zAnyExpressionsReporter.on_file   s     )]$
 
 
 	G070Kt}-#G$4$;$;$=$=>>DDUEZ[['*>>/'2KKgU	q==*19)=DK&&& =r7   c                V    |                                   |                                  d S r,   )_report_any_exprs_report_types_of_anysr_   s    r5   rN   z AnyExpressionsReporter.on_finish   s,       ""$$$$$r7   r   header	list[str]rowslist[list[str]]footerc           
     8   t          |          t          fd|||gz   D                       sJ d}dgz  }|||gz   D ]=}t          |          D ]+\  }}	t          ||         t          |	                    ||<   ,>t          |          D ]\  }}
|dk    r|
|z   ||<   t	          t
          j                            | j        |          d          5 } dt          |          z  j	        t          j        t          ||            }dt          |          z  }|                    |dz              |                    |dz              |D ]N} dt          |          z  j	        t          j        t          ||            }|                    |dz              O|                    |dz               dt          |          z  j	        t          j        t          ||            }|                    |dz              d d d            d S # 1 swxY w Y   d S )	Nc              3  >   K   | ]}t          |          k    V  d S r,   r   )r   rowrow_lens     r5   r   z;AnyExpressionsReporter._write_out_report.<locals>.<genexpr>   s.      JJ33s88w&JJJJJJr7   r   r   r   z{:>{}}-r   )r   allr|   maxr{   rt   rl   r   rX   r=   	itertoolschainzipr   )r2   r   r   r   r   min_column_distancewidthsr   r   valuer   r   
header_str	separator
row_valuesr
footer_strr   s                    @r5   _write_out_reportz(AnyExpressionsReporter._write_out_report   sy    f++JJJJ$&&9I2IJJJJJJJJ66** 	7 	7C%cNN 7 75q	3u::66q		7f%% 	4 	4DAq1uu 33q	"',,t993?? 
	'18(S[[08)/3vW]K^K^:_`Jc*oo-IGGJ%&&&GGI$%%%" " "
3XF+3Y_c*V\F]F]5^_D!!!!GGI$%%%8(S[[08)/3vW]K^K^:_`JGGJ%&&&
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	' 
	's   D,HHHc                   t          d | j                                        D                       }t          d | j                                        D                       }d}|dk    r%t          ||z
            t          |          z  dz  }g d}g }t	          | j                  D ]p}| j        |         \  }}t          ||z
            t          |          z  dz  }	|	dd}
|                    |t          |          t          |          |
g           q|                    d	 
           dt          |          t          |          |ddg}|                     d|||           d S )Nc              3      K   | ]	\  }}|V  
d S r,   rU   )r   r   _s      r5   r   z;AnyExpressionsReporter._report_any_exprs.<locals>.<genexpr>  s&      GGJGQGGGGGGr7   c              3      K   | ]	\  }}|V  
d S r,   rU   )r   r   totals      r5   r   z;AnyExpressionsReporter._report_any_exprs.<locals>.<genexpr>  s&      DD81eDDDDDDr7   g      Y@r   d   )NameAnysExprsCoveragez.2f%c                    | d         S r   rU   xs    r5   <lambda>z:AnyExpressionsReporter._report_any_exprs.<locals>.<lambda>#  
    ! r7   keyTotalzany-exprs.txt)	r   r   r   floatr/   rA   r&   sortr   )r2   	total_any
total_exprtotal_coveragecolumn_namesr   r   r   r   coveragecoverage_str	total_rows               r5   r   z(AnyExpressionsReporter._report_any_exprs  s   GG$+2D2D2F2FGGGGG	DDt{/A/A/C/CDDDDD
>>#J$:;;eJ>O>OOSVVN<<< "t{++ 	P 	PH#';x#8 Wii'122U95E5EELH&----LKK3w<<YNOOOO		nn	%%%c)nnc*oo.?W?W?W?WX	dINNNNNr7   c                :  	
 t          j                    
| j                                        D ],		                                D ]\  }}
|xx         |z  cc<   -d}d}|gt          t                                                    z   }g }| j                                        D ]/\  }	|                    |g	fdt          D             z              0|                    d            |g
fdt          D             z   }| 	                    d|||           d S )Nr   r  c                :    g | ]}t          |                   S rU   r&   )r   typcounters     r5   
<listcomp>z@AnyExpressionsReporter._report_types_of_anys.<locals>.<listcomp>1  s%    %X%X%XCc'#,&7&7%X%X%Xr7   c                    | d         S r   rU   r   s    r5   r   z>AnyExpressionsReporter._report_types_of_anys.<locals>.<lambda>2  r   r7   r  c                :    g | ]}t          |                   S rU   r  )r   r  total_counters     r5   r  z@AnyExpressionsReporter._report_types_of_anys.<locals>.<listcomp>3  s&    '`'`'`CM#,>(?(?'`'`'`r7   ztypes-of-anys.txt)
collectionsCounterr   r   r0   r   r   rA   r  r   )r2   any_typer   file_column_nametotal_row_namer	  r   r   r  r  r  s            @@r5   r   z,AnyExpressionsReporter._report_types_of_anys'  sR   2=2E2G2G-4466 	1 	1G#*==?? 1 1%h'''50''''1! ()D1E1L1L1N1N,O,OO "!%!7!=!=!?!? 	Z 	ZHgKK
%X%X%X%XCW%X%X%XXYYYY		nn	%%%#$'`'`'`'`K_'`'`'``	2L$	RRRRRr7   r`   rP   rQ   )
r   r&   r   r   r   r   r   r   r)   r*   )rR   rS   rT   __doc__r6   rL   rN   r   r   r   r   r   s   @r5   r   r      s        ==I I I I I I
> > > >0% % % %' ' ' '4O O O O$S S S S S S S Sr7   r   z	any-exprsc                  0     e Zd ZddZdd	Zd fdZ xZS )LineCoverageVisitorsourcer   r)   r*   c                6    || _         d |D             | _        d S )Nc                    g | ]}d S ))r   TrU   )r   ls     r5   r  z0LineCoverageVisitor.__init__.<locals>.<listcomp>C  s    999Qj999r7   )r  lines_covered)r2   r  s     r5   r6   zLineCoverageVisitor.__init__;  s'     :9&999r7   line_numberint
int | Nonec                    | j         |         }d}t          |          D ]5}|dk    r|dz  }|dk    rd|dz   dz  z  } |dk    r dS |dk    r dS |c S dS )	zReturn the indentation of a line of the source (specified by
        zero-indexed line number). Returns None for blank lines or comments.r   r   ry   	   #Nr   )r  r   )r2   r#  lineindentchars        r5   indentation_levelz%LineCoverageVisitor.indentation_levelO  s     {;'JJ 	 	Ds{{!vza/0tttt  tr7   r   r   c                F   |j         dz
  }d }|t          | j                  k     r5|                     |          }|n|dz  }|t          | j                  k     5|d S |dz   }|}|t          | j                  k     rD|                     |          }||dz  }n||k    r|dz  }|}nn|t          | j                  k     D|j        d u}t          ||          D ]$}| j        |         \  }	}
|	|k    r||f| j        |<   %t                                          |           d S r   )	r*  r   r  r-  r   r   r"  r   r   )r2   r   
start_linestart_indentcur_lineend_line
cur_indentis_typedr*  
old_indentr   r   s              r5   r   z"LineCoverageVisitor.visit_func_defg  sk   Y]
 3t{++++11*==L'!OJ	 3t{++++ F>T[))))//99J!Al**A#  T[)))) 9D(*h// 	D 	DD .t4MJ
 \)),8(+C"4( 	t$$$$$r7   )r  r   r)   r*   )r#  r$  r)   r%  r   )rR   rS   rT   r6   r-  r   r   r   s   @r5   r  r  :  se        : : : :(   0+% +% +% +% +% +% +% +% +% +%r7   r  c                  4     e Zd ZdZd fdZddZddZ xZS )LineCoverageReportera[  Exact line coverage reporter.

    This reporter writes a JSON dictionary with one field 'lines' to
    the file 'coverage.json' in the specified report directory. The
    value of that field is a dictionary which associates to each
    source file's absolute pathname the list of line numbers that
    belong to typed functions in that file.
    rW   r   rX   r&   r)   r*   c                Z    t                                          ||           i | _        d S r,   )r   r6   r"  r   s      r5   r6   zLineCoverageReporter.__init__  s+    *---35r7   rE   r   rF   rG   rH   rI   rJ   r   c                   t          |j                  5 }|                                }d d d            n# 1 swxY w Y   t          |          }|                    |           g }t          |j                  D ]"\  }	\  }
}|r|                    |	dz              #|| j        t          j        	                    |j                  <   d S r   )
r{   rl   r   r  r   r|   r"  rA   rt   abspath)r2   rE   rF   rH   rJ   r   tree_sourcecoverage_visitorcovered_linesr#  r   typeds               r5   rL   zLineCoverageReporter.on_file  s    $)__ 	(++--K	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( /{;;$%%%'01A1O'P'P 	6 	6#K!U 6$$[1_5559F27??4955666s   6::c                    t          t          j                            | j        d          d          5 }t          j        d| j        i|           d d d            d S # 1 swxY w Y   d S )Nzcoverage.jsonr   lines)r{   rt   rl   r   rX   jsondumpr"  )r2   r   s     r5   rN   zLineCoverageReporter.on_finish  s    "',,t@@#FF 	8!Iw 23Q777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   AA"%A"r`   rP   rQ   rR   rS   rT   r  r6   rL   rN   r   r   s   @r5   r7  r7    ss         6 6 6 6 6 6G G G G(8 8 8 8 8 8 8 8r7   r7  linecoveragec                  &    e Zd ZddZddZdd
ZdS )FileInfonamer&   moduler)   r*   c                f    || _         || _        dgt          t          j                  z  | _        d S r   )rG  rH  r   r   precision_namesr   )r2   rG  rH  s      r5   r6   zFileInfo.__init__  s-    	cC 5666r7   r$  c                *    t          | j                  S r,   )r   r   r_   s    r5   r   zFileInfo.total  s    4;r7   r(   c                n    d t          t          t          j        | j                            D             S )Nc                4    i | ]\  }}|t          |          S rU   r  )r   rG  vals      r5   
<dictcomp>z#FileInfo.attrib.<locals>.<dictcomp>  s$    ```94c#hh```r7   )r/   r   r   rJ  r   r_   s    r5   attribzFileInfo.attrib  s/    ``s5;PRVR]7^7^0_0_````r7   N)rG  r&   rH  r&   r)   r*   )r)   r$  )r)   r(   )rR   rS   rT   r6   r   rP  rU   r7   r5   rF  rF    sV        7 7 7 7
       a a a a a ar7   rF  c                       e Zd ZU dZd fdZe                    d	                    d
  ed          D                       d          Z	de
d<   ddZed d            Zd!dZ xZS )"MemoryXmlReporterz}Internal reporter that generates XML in memory.

    This is used by all other XML-based reporters to avoid duplication.
    rW   r   rX   r&   r)   r*   c                   t                                          ||           t          j                            |j        dd          | _        t          j                            |j        dd          | _        t          j                            |j        dd          | _        t          j                            |j        dd          }t          j
        t          j        |                    | _        d | _        g | _        d S )Nxmlmypy-html.xsltzmypy-txt.xsltmypy-html.csszmypy.xsd)r   r6   rt   rl   r   r%   xslt_html_pathxslt_txt_pathcss_html_pathr   	XMLSchemaparseschemalast_xmlfiles)r2   rW   rX   xsd_pathr   s       r5   r6   zMemoryXmlReporter.__init__  s    *--- gll7+;UDTUUW\\'*:E?SSW\\'*:E?SS7<< 0%DDoek(&;&;<<$(%'


r7    c              #  @   K   | ]}|d k    t          |          V  dS )	   N)chr)r   r   s     r5   r   zMemoryXmlReporter.<genexpr>  s-      0U0UAaSTffQffff0U0Ur7       z???????????????????????????????r
   control_fixerrE   r   rF   rG   rH   rI   rJ   r   c           
        d | _         	 t          j                            |j                  }n# t          $ r Y d S w xY wt          |          st          j                            |          rd S t          j        d|j	        ||d          }|
                    |           t          j        d||j                  }t          j        |          }t          ||j                  }	t!          |          D ]\  }
}|j                            |
t          j                  }|	j        |xx         dz  cc<   t          j        |d|                     ||
          |                    d                              | j                  t5          |
          t          j        |                    t          j                            d	|          }t          j        d
dt;          |           d          }|                    |           | j                             |           || _         | j!        "                    |	           d S )NTr   r   rF   r   r   zmypy-report-file)rG  rH  ry   r*  r   )any_infocontentnumber	precisionrU  xml-stylesheettype="text/xsl" href="")#r]  rt   rl   relpath
ValueErrorrv   isdirr   r   r   r   r   Elementr   ElementTreerF  r   r   get
TYPE_EMPTYr   
SubElement_get_any_info_for_linerstrip	translatere  r&   rJ  ProcessingInstructionr   addpreviousr\  assertValidr^  rA   )r2   rE   rF   rH   rJ   rl   r   rootdoc	file_infolineno	line_textstatus	xslt_pathtransform_pis                  r5   rL   zMemoryXmlReporter.on_file  sA    	7??49--DD 	 	 	FF	 D!! 	RW]]4%8%8 	F)]
 
 
 	G}/d4>RRR%%T4>22	!5d!;!; 
	 
	FI%))&%2BCCFV$$$)$$$44WfEE!((..889KLL6{{/7     GOO$4d;;	2Q|I7N7NQQQ
 
 	&&&$$$
)$$$$$s   $. 
<<r   stats.StatisticsVisitorr  r$  c                    || j         v rmd}t          j                    }| j         |         D ]}||j        xx         dz  cc<   |                                D ]\  }}|dt
          |          d| dz  }|S dS )NzAny Types on this line: ry   r   z (x)zNo Anys on this line!)any_line_mapr  r  type_of_anyr0   r   )r   r  resultr  r  r  occurrencess          r5   rw  z(MemoryXmlReporter._get_any_info_for_line  s    W)))/F0;0C0E0EG+F3 . .(((A-(((()0 Q Q%+P3H=PP+PPPPM**r7   c                \   d | _         t          | j        d           }t          j        dd          }t          j        |          }|D ]d}t          j        |d|                                |j        t          |j
                  t          |                                                     et          j                            dd	          }t          j        d
dt          |           d          }|                    |           | j                            |           || _         d S )Nc                    | j         S r,   rH  r   s    r5   r   z-MemoryXmlReporter.on_finish.<locals>.<lambda>&       r7   r  zmypy-report-indexindex)rG  r9   )rH  rG  r   rU  .rl  rm  rn  )r]  r/   r^  r   rr  rs  rv  rP  rH  r   rG  r&   r   rt   rl   ro  rz  r{  r\  r|  )r2   output_filesr}  r~  r  r  r  s          r5   rN   zMemoryXmlReporter.on_finish#  s+   dj.@.@AAA}0w???%%% 	 	I  "" '!).11)//++,,     GOO$4c::	2Q|I7N7NQQQ
 
 	&&&$$$r7   r`   rP   )r   r  r  r$  r)   r&   rQ   )rR   rS   rT   r  r6   r&   	maketransr   r   re  __annotations__rL   staticmethodrw  rN   r   r   s   @r5   rR  rR    s          
	( 	( 	( 	( 	( 	( ==0U0Ur0U0U0U)U)UW_``M````2% 2% 2% 2%h 
+ 
+ 
+ \
+       r7   rR  
memory-xml)rC   r=  r$  total_linesc                :    |dk    rt          d          S | |z  dS )Nr   g      ?z.4fr  )r=  r  s     r5   get_line_rater  A  s)    a3xx+-333r7   c                  *    e Zd ZdZddZddZdd
ZdS )CoberturaPackagezMContainer for XML and statistics mapping python modules to Cobertura package.rG  r&   r)   r*   c                L    || _         i | _        i | _        d| _        d| _        d S r   )rG  classespackagesr  r=  )r2   rG  s     r5   r6   zCoberturaPackage.__init__K  s-    	')57r7   r   c                X   t          j        dd| j                  }d|j        d<   t	          | j        | j                  |j        d<   t          j        |d          }t          | j	                  D ]"}|
                    | j	        |                    #|                     |           |S )Npackage1.0)
complexityrG  0branch-rate	line-rater  )r   rr  rG  rP  r  r=  r  rv  r/   r  rA   add_packages)r2   package_elementclasses_element
class_names       r5   as_xmlzCoberturaPackage.as_xmlR  s    -	e$)TTT03}-.;D<NPTP`.a.a{+*?IFF .. 	= 	=J""4<
#;<<<</***r7   parent_elementc                    | j         rtt          j        |d          }t          | j                                         t          d                    D ]+}|                    |                                           *d S d S )Nr  rG  r  )r  r   rv  r/   r   r   rA   r  )r2   r  packages_elementr  s       r5   r  zCoberturaPackage.add_packages\  s    = 	:$/
KK!$-"6"6"8"8j>P>PQQQ : : ''(8(89999	: 	:: :r7   N)rG  r&   r)   r*   )r)   r   )r  r   r)   r*   )rR   rS   rT   r  r6   r  r  rU   r7   r5   r  r  H  sV        WW      : : : : : :r7   r  c                  4     e Zd ZdZd fdZddZddZ xZS )CoberturaXmlReporterz0Reporter for generating Cobertura compliant XML.rW   r   rX   r&   r)   r*   c           	     H   t                                          ||           t          j        dt	          t          t          j                                        t                    | _        t          j	        | j                  | _
        t          d          | _        d S )Nr
  )	timestampversionr  )r   r6   r   rr  r&   r$  timer   r}  rs  r~  r  root_packager   s      r5   r6   zCoberturaXmlReporter.__init__f  sv    *---M*C	<L<L8M8MWbccc	$TY//,S11r7   rE   r   rF   rG   rH   rI   rJ   r   c           
     Z   t           j                            |j                  }t          j        d|j        ||d          }|                    |           t           j                            |          }t          ||j	                  }t          j        dd||          }	t          j        |	d           t          j        |	d          }
d}d}t          |          D ]\  }}|j                            |t          j                  }d}d	}|t          j        k    r?|d
z  }|t          j        k    r|d
z  }d
}|t          j        k    rd}|j        |xx         d
z  cc<   t          j        |
dt)          |                                          t)          |          t)          |          t          j        |                   }|r
d|j        d<   d|	j        d<   t1          ||          |	j        d<   |j                            dd
          d         }|j                            d          r|j        }|| j        j        vrt?          |          | j        j        |<   | j        j        |         }| j        |g}|D ]"}|xj         |z  c_         |xj!        |z  c_!        #|	|j"        |<   d S )NTrg  classr  )r  r   rG  methodsr@  r   Fry   r*  )branchhitsrj  rk  z	50% (1/2)zcondition-coverager  r  r  r  z__init__.py)#rt   rl   ro  r   r   r   r   basenamerF  r   r   rr  rv  r   r   rt  ru  TYPE_ANYTYPE_IMPRECISEr   r&   lowerrJ  rP  r  rH  rsplitrG  endswithr  r  r  r  r=  r  )r2   rE   rF   rH   rJ   rl   r   r  r  class_elementlines_elementclass_lines_coveredclass_total_linesr  r   r  r  r  line_elementparent_modulecurrent_packagepackages_to_updater  s                          r5   rL   zCoberturaXmlReporter.on_filem  s    wty)))]
 
 
 	GW%%d++
T4>22	g%$U_```	222(@@-d33 	H 	HIFA%))&%2BCCFDF)))"''#q(#---V$$$)$$$ +6{{((**YY6{{/7  L  H<G#$89.1]+,9:MO`,a,a[) "(//Q77:>""=11 	-%,M 1 :::8H8W8WD&}5+4]C"/A) 	9 	9G#44!!%88!!!.;
+++r7   c                0   t          | j        j        | j        j                  | j        j        d<   d| j        j        d<   t          j        | j        d          }t          j        |d          }t          j	                    |_
        | j                            | j                   t          j                            | j        d          }| j                            |dd	           t#          d
t          j                            |                     d S )Nr  r  r  sourcesr  zcobertura.xmlutf-8T)encodingpretty_printzGenerated Cobertura report:)r  r  r=  r  r}  rP  r   rv  rt   getcwdtextr  rl   r   rX   r~  r   r<   r:  )r2   r  source_elementout_paths       r5   rN   zCoberturaXmlReporter.on_finish  s    (5+T->-J)
 )
	% +.	'"49i88)'8<< ikk&&ty1117<<AAx'EEE+RW__X-F-FGGGGGr7   r`   rP   rQ   rC  r   s   @r5   r  r  c  sx        ::2 2 2 2 2 2@< @< @< @<DH H H H H H H Hr7   r  zcobertura-xmlc                  $     e Zd ZdZd	 fdZ xZS )
AbstractXmlReporterz8Internal abstract class for reporters that work via XML.rW   r   rX   r&   r)   r*   c                    t                                          ||           |                    dd          }t          |t                    sJ || _        d S )Nr  rZ   )r   r6   r1   
isinstancerR  
memory_xml)r2   rW   rX   memory_reporterr   s       r5   r6   zAbstractXmlReporter.__init__  sT    *---!,,\:FF/+<=====)r7   r`   )rR   rS   rT   r  r6   r   r   s   @r5   r  r    sC        BB* * * * * * * * * *r7   r  c                  "    e Zd ZdZddZddZdS )XmlReporteraC  Public reporter that exports XML.

    The produced XML files contain a reference to the absolute path
    of the html transform, so they will be locally viewable in a browser.

    However, there is a bug in Chrome and all other WebKit-based browsers
    that makes it fail from file:// URLs but work on http:// URLs.
    rE   r   rF   rG   rH   rI   rJ   r   r)   r*   c                ~   | j         j        }|d S t          j                            |j                  }|                    d          rd S t          j                            | j        d|dz             }t          j	        t          j        
                    |                     |                    |d           d S )Nrn   rT  z.xmlr  r  )r  r]  rt   rl   ro  rr   r   rX   r   r[   dirnamer   )r2   rE   rF   rH   rJ   r]  rl   r  s           r5   rL   zXmlReporter.on_file  s     ?+Fwty))??4   	F7<<vFF 9 9:::x'22222r7   c                   | j         j        }|J t          j                            | j        d          }t          j                            | j        d          }t          j                            | j        d          }|                    |d           t          j        | j         j	        |           t          j        | j         j
        |           t          dt          j                            |                     d S )Nz	index.xmlrU  rV  r  r  zGenerated XML report:)r  r]  rt   rl   r   rX   r   shutilcopyfilerW  rY  r<   r:  )r2   r]  r  out_xsltout_csss        r5   rN   zXmlReporter.on_finish  s    ?+###7<<==7<<1ABB',,t@@x'2226AAA5w???%rwx'@'@AAAAAr7   NrP   rQ   )rR   rS   rT   r  rL   rN   rU   r7   r5   r  r    sL         3 3 3 3"	B 	B 	B 	B 	B 	Br7   r  rT  c                  4     e Zd ZdZd fdZddZddZ xZS )XsltHtmlReporterzPublic reporter that exports HTML via XSLT.

    This is slightly different than running `xsltproc` on the .xml files,
    because it passes a parameter to rewrite the links.
    rW   r   rX   r&   r)   r*   c                    t                                          ||           t          j        t          j        | j        j                            | _        t          j                            d          | _	        d S )Nhtml)
r   r6   r   XSLTr[  r  rW  	xslt_htmlstrparam
param_htmlr   s      r5   r6   zXsltHtmlReporter.__init__  sX    *---EK0N$O$OPP*--f55r7   rE   r   rF   rG   rH   rI   rJ   r   c                   | j         j        }|d S t          j                            |j                  }|                    d          rd S t          j                            | j        d|dz             }t          j	        t          j        
                    |                     t          |                     || j                            }t          |d          5 }	|	                    |           d d d            d S # 1 swxY w Y   d S )Nrn   r  z.htmlextwb)r  r]  rt   rl   ro  rr   r   rX   r   r[   r  bytesr  r  r{   r   )
r2   rE   rF   rH   rJ   r]  rl   r  transformed_htmlout_files
             r5   rL   zXsltHtmlReporter.on_file  s'    ?+Fwty))??4   	F7<<HH 9 9::: do!N!NOO(D!! 	-XNN+,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   DD	Dc                   | j         j        }|J t          j                            | j        d          }t          j                            | j        d          }t          |                     || j                            }t          |d          5 }|
                    |           d d d            n# 1 swxY w Y   t          j        | j         j        |           t          dt          j                            |                     d S )Nz
index.htmlrV  r  r  z!Generated HTML report (via XSLT):)r  r]  rt   rl   r   rX   r  r  r  r{   r   r  r  rY  r<   r:  )r2   r]  r  r  r  r  s         r5   rN   zXsltHtmlReporter.on_finish  s   ?+###7<<>>',,t@@ do!N!NOO(D!! 	-XNN+,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-5w???127??83L3LMMMMMs   B66B:=B:r`   rP   rQ   rC  r   s   @r5   r  r    sw         6 6 6 6 6 6- - - -&	N 	N 	N 	N 	N 	N 	N 	Nr7   r  z	xslt-htmlc                  4     e Zd ZdZd fdZddZddZ xZS )XsltTxtReporterzvPublic reporter that exports TXT via XSLT.

    Currently this only does the summary, not the individual reports.
    rW   r   rX   r&   r)   r*   c                    t                                          ||           t          j        t          j        | j        j                            | _        d S r,   )r   r6   r   r  r[  r  rX  xslt_txtr   s      r5   r6   zXsltTxtReporter.__init__+  sA    *---
5;t/L#M#MNNr7   rE   r   rF   rG   rH   rI   rJ   r   c                    d S r,   rU   r]   s        r5   rL   zXsltTxtReporter.on_file0  s	     	r7   c                   | j         j        }|J t          j                            | j        d          }t          |                     |                    }t          |d          5 }|	                    |           d d d            n# 1 swxY w Y   t          dt          j                            |                     d S )Nz	index.txtr  z Generated TXT report (via XSLT):)r  r]  rt   rl   r   rX   r  r  r{   r   r<   r:  )r2   r]  r  transformed_txtr  s        r5   rN   zXsltTxtReporter.on_finish9  s    ?+###7<<==h 7 788(D!! 	,XNN?+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,0"'//(2K2KLLLLLs   (B

BBr`   rP   rQ   rC  r   s   @r5   r  r  %  s}         
O O O O O O
   M M M M M M M Mr7   r  zxslt-txtr  txtc                  4     e Zd ZdZd fdZddZddZ xZS )LinePrecisionReportera  Report per-module line counts for typing precision.

    Each line is classified into one of these categories:

    * precise (fully type checked)
    * imprecise (Any types in a type component, such as List[Any])
    * any (something with an Any type, implicit or explicit)
    * empty (empty line, comment or docstring)
    * unanalyzed (mypy considers line unreachable)

    The meaning of these categories varies slightly depending on
    context.
    rW   r   rX   r&   r)   r*   c                Z    t                                          ||           g | _        d S r,   )r   r6   r^  r   s      r5   r6   zLinePrecisionReporter.__init__X  s(    *---%'


r7   rE   r   rF   rG   rH   rI   rJ   r   c                   	 t           j                            |j                  }n# t          $ r Y d S w xY wt	          |          rd S t          j        d|j        ||d          }|                    |           t          ||j
                  }t          |          D ]?\  }}	|j                            |t
          j                  }
|j        |
xx         dz  cc<   @| j                            |           d S )NTrg  ry   )rt   rl   ro  rp  rv   r   r   r   r   rF  r   r   r   rt  ru  r   r^  rA   )r2   rE   rF   rH   rJ   rl   r   r  r  r   r  s              r5   rL   zLinePrecisionReporter.on_file\  s   	7??49--DD 	 	 	FF	 D!! 	F)]
 
 
 	GT4>22	-d33 	* 	*IFA%))&%2BCCFV$$$)$$$$
)$$$$$s   $' 
55c                `   | j         sd S t          | j         d           }t          j                            | j        d          }t          dt          d |D                                 }d}|ft          d |D                       z   }d|z  }t          |d	          5 }|	                     |j
        d
g|R             |	                    d|dz   z  dz              |D ]}|j        }	|	                    |
                    |j                            |          |                                |	t          j                 |	t          j                 |	t          j                 |	t          j                 |	t          j                                      	 d d d            d S # 1 swxY w Y   d S )Nc                    | j         S r,   r  r   s    r5   r   z1LinePrecisionReporter.on_finish.<locals>.<lambda>  r  r7   r  zlineprecision.txtr   c              3  >   K   | ]}t          |j                  V  d S r,   )r   rH  )r   infos     r5   r   z2LinePrecisionReporter.on_finish.<locals>.<genexpr>  s,      EE3t{++EEEEEEr7   )LinesPrecise	Impreciser   Empty
Unanalyzedc              3  4   K   | ]}t          |          V  d S r,   r   )r   ts     r5   r   z2LinePrecisionReporter.on_finish.<locals>.<genexpr>  s(      !9!9Q#a&&!9!9!9!9!9!9r7   z0{:%d}  {:%d}  {:%d}  {:%d}  {:%d}  {:%d}  {:%d}
r   r   r   3   r   )r^  r/   rt   rl   r   rX   r   r   r{   r   r=   r   rH  ljustr   r   TYPE_PRECISEr  r  ru  r   )
r2   r  report_filewidthtitlesr   fmtr   r  r   s
             r5   rN   zLinePrecisionReporter.on_finish{  s   z 	Fdj.@.@AAAgll4?4GHHAsEEEEEEEFFPE!9!9&!9!9!9999AFJ+s## 	qGGJCJv////000GGC52:&-...)  	")JJ!(..u55!))u12u34u~.u/0u45 
 
 
 
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   !C4F##F'*F'r`   rP   rQ   rC  r   s   @r5   r  r  I  so         ( ( ( ( ( (% % % %>       r7   r  lineprecision)F)rb   r&   rD   rc   rC   rd   r)   r*   )rh   r&   ri   r&   r)   r*   )rl   r&   r)   rd   )rl   r&   r)   rw   )r=  r$  r  r$  r)   r&   )Ur  
__future__r   r  r   rA  rt   r  r>   r  rz   abcr   r   operatorr   typingr   r   r	   r
   r   r   typing_extensionsr   r!   urllib.requestr   mypyr   mypy.defaultsr   
mypy.nodesr   r   r   mypy.optionsr   mypy.traverserr   
mypy.typesr   r   mypy.versionr   lxmlr   r;   r@   OrderedDictunannotatedexplicitfrom_unimported_typefrom_omitted_generics
from_errorspecial_formimplementation_artifactr   r  r&   rd   r"   r#   r   r    rg   rk   rv   r   r   r   r   r  r7  rF  rR  r  r  r  r  r  r  r  r  setrU   r7   r5   <module>r'     sM   ; ; ; " " " " " "          				  



   ' ' ' ' ' ' ' '       > > > > > > > > > > > > > > > > 5 5 5 5 5 5 ' ' ' ' ' '       ( ( ( ( ( ( 4 4 4 4 4 4 4 4 4 4             + + + + + + & & & & & & & & $ $ $ $ $ $NN   NNN BYAX		.		Z(		'6		(*<=		w'		0		*,EF
B 
B  
 
 
 
 #xC(*<<=tC	DD     ,.  - - - -*! *! *! *! *! *! *! *!Z        0 ; ; ; ; ;J J J J      0 0 0 0 0) 0 0 01F 1F 1F 1F 1F( 1F 1F 1Fh  +0 1 1 1]S ]S ]S ]S ]S- ]S ]S ]S@  +5 6 6 6X% X% X% X% X%* X% X% X%v$8 $8 $8 $8 $8+ $8 $8 $8N  ."6 7 7 7
a 
a 
a 
a 
a 
a 
a 
ao o o o o( o o od  , 1d C C C C4 4 4 4: : : : : : : :6WH WH WH WH WH+ WH WH WHt  /#7D I I I I	* 	* 	* 	* 	** 	* 	* 	*$B $B $B $B $B% $B $B $BN  % 6 6 6 6)N )N )N )N )N* )N )N )NX  +/D A A A AM M M M M) M M M<  *o$ ? ? ? ? {F # # # z5 ! ! !K K K K K, K K K\  /#8 9 9 9
 sN 3 3333333s   B BB