o
    2g                  
   @  s~  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, z
ddl-m.Z. dZ/W n e0y   dZ/Y nw e1e*j2dfe*j3dfe*j4dfe*j5dfe*j6dfe*j7dfe*j8d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 dZ?G d#d ded$Z@	dfdgd-d.ZAdhd1d2ZBdid4d5ZCdjd7d8ZDG d9d: d:e'ZEG d;d< d<e@ZFeAd=eF G d>d? d?e@ZGeAd@eG G dAdB dBe'ZHG dCdD dDe@ZIeAdEeI G dFdG dGZJG dHdI dIe@ZKeAdJeKddK dkdOdPZLG dQdR dRZMG dSdT dTe@ZNeAdUeNddK G dVdW dWe@ZOG dXdY dYeOZPeAdZePddK G d[d\ d\eOZQeAd]eQddK G d^d_ d_eOZReAd`eRddK eBd]da eBd`db G dcdd dde@ZSeAdeeS eTe>eTeksJ dS )lz5Classes 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                   @  s4   e Zd ZdddZdddZdddZdddZdS )r   data_dirstrreport_dirsdict[str, str]returnNonec                 C  s8   || _ g | _i | _t| D ]
\}}| || qd S N)r#   	reportersnamed_reporterssorteditems
add_report)selfr#   r%   report_type
report_dir r2   C/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/report.py__init__6   s   zReports.__init__r0   r1   r   c                 C  sp   z| j | W S  ty   Y nw t| \}}|r&ts&td|tjd 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)r/   r0   r1   reporter_cls
needs_lxmlreporterr2   r2   r3   r.   >   s"   

zReports.add_reporttreer   modulesdict[str, MypyFile]type_mapdict[Expression, Type]optionsr   c                 C  s    | j D ]
}||||| qd S r)   )r*   on_file)r/   rA   rB   rD   rF   r@   r2   r2   r3   r5   S   s   
zReports.filec                 C  s   | j D ]}|  qd S r)   )r*   	on_finish)r/   r@   r2   r2   r3   finish]   s   

zReports.finishN)r#   r$   r%   r&   r'   r(   )r0   r$   r1   r$   r'   r   
rA   r   rB   rC   rD   rE   rF   r   r'   r(   r'   r(   )__name__
__module____qualname__r4   r.   r5   rI   r2   r2   r2   r3   r   5   s
    



c                   @  s2   e Zd ZdddZedddZedddZdS )r   reportsr   
output_dirr$   r'   r(   c                 C  s$   || _ |dkrtj|dd d S d S )N<memory>Texist_ok)rP   osmakedirsr/   rO   rP   r2   r2   r3   r4   c   s   zAbstractReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c                 C     d S r)   r2   r/   rA   rB   rD   rF   r2   r2   r3   rG   h   s   zAbstractReporter.on_filec                 C  rW   r)   r2   r/   r2   r2   r3   rH   r   s   zAbstractReporter.on_finishNrO   r   rP   r$   r'   r(   rJ   rK   )rL   rM   rN   r4   r   rG   rH   r2   r2   r2   r3   r   b   s    
	)	metaclassreport_namer$   r@   *Callable[[Reports, str], AbstractReporter]r?   boolr'   r(   c                 C  s   ||ft | < d S r)   r"   )r\   r@   r?   r2   r2   r3   register_reporterw   s   r`   source_reportertarget_reporterc                 C  s   t |  t |< d S r)   r_   )ra   rb   r2   r2   r3   alias_reporter   s   rc   pathc                 C  sB   t | 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splitrT   sep)rd   r2   r2   r3   should_skip_path   s   

rl   Iterator[tuple[int, str]]c                 c  s\    z"t | }t|dE dH  W d   W dS 1 sw   Y  W dS  ty-   Y dS w )zDReturn an iterator over (line number, line text) from a Python file.   N)tokenizeopen	enumerateIsADirectoryError)rd   
input_filer2   r2   r3   iterate_python_lines   s   &rt   c                      s(   e Zd Zd	 fddZd
ddZ  ZS )FuncCounterVisitorr'   r(   c                   s   t    ddg| _d S Nr   superr4   countsrY   	__class__r2   r3   r4      s   
zFuncCounterVisitor.__init__defnr   c                 C  s   | j |jd u  d7  < d S Nrn   )ry   type)r/   r|   r2   r2   r3   visit_func_def      z!FuncCounterVisitor.visit_func_defrK   r|   r   r'   r(   )rL   rM   rN   r4   r   __classcell__r2   r2   rz   r3   ru      s    ru   c                      s2   e Zd Zd fddZdddZdddZ  ZS )LineCountReporterrO   r   rP   r$   r'   r(   c                      t  || i | _d S r)   rw   rV   rz   r2   r3   r4         
zLineCountReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c                 C  s   zt |jd}t| }W d    n1 sw   Y  W n ty)   d}Y nw t }|| |j\}}	|	| }
|jr@d}	|
rH||	 |
 n|}|||	|
f| j|j	< d S )Nrbr   )
rp   rd   len	readlinesrr   ru   acceptry   ignore_errors	_fullname)r/   rA   rB   rD   rF   fphysical_linesfunc_counterunannotated_funcsannotated_funcstotal_funcsimputed_annotated_linesr2   r2   r3   rG      s*   	

zLineCountReporter.on_filec                   s   t dd | j D dd t fddtdD }ttj| j	dd8}|
d	j|   D ]$\}}|
|d
 dd|d dd|d dd|d dd| d
 q1W d    d S 1 saw   Y  d S )Nc                 s  s    | ]	\}}||fV  qd S r)   r2   ).0pcr2   r2   r3   	<genexpr>       z.LineCountReporter.on_finish.<locals>.<genexpr>T)reversec                 3  s&    | ] t  fd dD V  qdS )c                 3  s    | ]	\}}|  V  qd S r)   r2   )r   r   r   ir2   r3   r      r   z8LineCountReporter.on_finish.<locals>.<genexpr>.<genexpr>N)sum)r   ry   r   r3   r      s   $    zlinecount.txtwz{:7} {:7} {:6} {:6} total
r   7 rn      6   
)r,   ry   r-   tuplerangerp   rT   rd   joinrP   writer9   )r/   total_countsr   r   r   r2   r   r3   rH      s   B"zLineCountReporter.on_finishrZ   rJ   rK   )rL   rM   rN   r4   rG   rH   r   r2   r2   rz   r3   r      s    
$r   	linecountc                      sT   e Zd ZdZd" fdd	Zd#ddZd$ddZd%ddZd$ddZd$d d!Z	  Z
S )&AnyExpressionsReporterz3Report frequencies of different kinds of Any types.rO   r   rP   r$   r'   r(   c                   s   t  || i | _i | _d S r)   )rx   r4   ry   any_types_counterrV   rz   r2   r3   r4      s   
zAnyExpressionsReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c           	      C  s   t jd|j||ddd}|| |j| j|j< t|j 	t j
}|j| }|j|j | }|dkr>||f| j|j< d S d S )NTF)inferredfilenamerB   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_exprsry   )	r/   rA   rB   rD   rF   visitornum_unanalyzed_linesnum_any	num_totalr2   r2   r3   rG      s    

zAnyExpressionsReporter.on_filec                 C  s   |    |   d S r)   )_report_any_exprs_report_types_of_anysrY   r2   r2   r3   rH      s   z AnyExpressionsReporter.on_finishr   header	list[str]rowslist[list[str]]footerc                   s  t | t fdd|||g D sJ d}dg  }|||g D ]}t|D ]\}}	t|| t |	||< q(q"t|D ]\}}
|dkrK|
| ||< q=ttj| j|dd}dt | j	t
jt||  }dt | }||d	  ||d	  |D ]}dt | j	t
jt||  }||d	  q}||d	  dt | j	t
jt||  }||d	  W d    d S 1 sw   Y  d S )
Nc                 3  s    | ]	}t | kV  qd S r)   r   )r   rowrow_lenr2   r3   r      r   z;AnyExpressionsReporter._write_out_report.<locals>.<genexpr>r   r   r   z{:>{}}-r   )r   allrq   maxrp   rT   rd   r   rP   r9   	itertoolschainzipr   )r/   r   r   r   r   min_column_distancewidthsr   r   valuer   r   
header_str	separator
row_valuesr
footer_strr2   r   r3   _write_out_report   s0   "
"z(AnyExpressionsReporter._write_out_reportc                 C  s   t dd | j D }t dd | j D }d}|dkr*t|| t| d }g d}g }t| jD ](}| j| \}}t|| t| d }	|	dd	}
||t|t||
g q5|jd
d d dt|t||dd	g}| d||| d S )Nc                 s  s    | ]\}}|V  qd S r)   r2   )r   r   _r2   r2   r3   r         z;AnyExpressionsReporter._report_any_exprs.<locals>.<genexpr>c                 s  s    | ]\}}|V  qd S r)   r2   )r   r   totalr2   r2   r3   r     r   g      Y@r   d   )NameAnysExprsCoveragez.2f%c                 S     | d S rv   r2   xr2   r2   r3   <lambda>#      z:AnyExpressionsReporter._report_any_exprs.<locals>.<lambda>keyTotalzany-exprs.txt)	r   ry   r   floatr,   r=   r$   sortr   )r/   	total_any
total_exprtotal_coveragecolumn_namesr   r   r   r   coveragecoverage_str	total_rowr2   r2   r3   r     s   z(AnyExpressionsReporter._report_any_exprsc           	        s   t  | j D ]   D ]\}}|  |7  < qq	d}d}|gtt  }g }| j D ]\} ||g fddtD   q1|jdd d |gfddtD  }| 	d	||| d S )
Nr   r   c                      g | ]}t  | qS r2   r$   r   typ)counterr2   r3   
<listcomp>1      z@AnyExpressionsReporter._report_types_of_anys.<locals>.<listcomp>c                 S  r   rv   r2   r   r2   r2   r3   r   2  r   z>AnyExpressionsReporter._report_types_of_anys.<locals>.<lambda>r   c                   r   r2   r   r   )total_counterr2   r3   r   3  r   ztypes-of-anys.txt)
collectionsCounterr   r   r-   r   r   r=   r   r   )	r/   any_typer   file_column_nametotal_row_namer   r   r   r   r2   )r   r   r3   r   '  s    z,AnyExpressionsReporter._report_types_of_anysrZ   rJ   rK   )
r   r$   r   r   r   r   r   r   r'   r(   )rL   rM   rN   __doc__r4   rG   rH   r   r   r   r   r2   r2   rz   r3   r      s    



r   z	any-exprsc                      s2   e Zd ZdddZdd
dZd fddZ  ZS )LineCoverageVisitorsourcer   r'   r(   c                 C  s   || _ dd |D | _d S )Nc                 S  s   g | ]}d qS ))r   Tr2   )r   lr2   r2   r3   r   C  s    z0LineCoverageVisitor.__init__.<locals>.<listcomp>)r  lines_covered)r/   r  r2   r2   r3   r4   ;  s   zLineCoverageVisitor.__init__line_numberint
int | Nonec                 C  sn   | j | }d}t|D ])}|dkr|d7 }q|dkr#d|d d  }q|dkr* dS |dkr1 dS |  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   rn   	   #Nr   )r  r   )r/   r  lineindentcharr2   r2   r3   indentation_levelO  s   

z%LineCoverageVisitor.indentation_levelr|   r   c                   s   |j d }d }|t| jk r#| |}|d urn|d7 }|t| jk s|d u r)d S |d }|}|t| jk rW| |}|d u rD|d7 }n||krO|d7 }|}nn|t| jk s6|jd u}t||D ]}| j| \}	}
|	|kru||f| j|< qat | d S r}   )	r  r   r  r  r~   r   r  rx   r   )r/   r|   
start_linestart_indentcur_lineend_line
cur_indentis_typedr  
old_indentr   rz   r2   r3   r   g  s8   




z"LineCoverageVisitor.visit_func_def)r  r   r'   r(   )r  r	  r'   r
  r   )rL   rM   rN   r4   r  r   r   r2   r2   rz   r3   r  :  s    

r  c                      6   e Zd ZdZd fdd	ZdddZdddZ  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.
    rO   r   rP   r$   r'   r(   c                   r   r)   )rx   r4   r  rV   rz   r2   r3   r4     r   zLineCoverageReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c                 C  s   t |j}| }W d    n1 sw   Y  t|}|| g }t|jD ]\}	\}
}|r8||	d  q)|| jtj	|j< d S r}   )
rp   rd   r   r  r   rq   r  r=   rT   abspath)r/   rA   rB   rD   rF   r   tree_sourcecoverage_visitorcovered_linesr  r   typedr2   r2   r3   rG     s   

zLineCoverageReporter.on_filec                 C  sN   t tj| jdd}td| ji| W d    d S 1 s w   Y  d S )Nzcoverage.jsonr   lines)rp   rT   rd   r   rP   jsondumpr  )r/   r   r2   r2   r3   rH     s   "zLineCoverageReporter.on_finishrZ   rJ   rK   rL   rM   rN   r  r4   rG   rH   r   r2   r2   rz   r3   r    s
    	
r  linecoveragec                   @  s*   e Zd ZdddZdd	d
ZdddZdS )FileInfonamer$   moduler'   r(   c                 C  s"   || _ || _dgttj | _d S rv   )r&  r'  r   r   precision_namesry   )r/   r&  r'  r2   r2   r3   r4     s   zFileInfo.__init__r	  c                 C  s
   t | jS r)   )r   ry   rY   r2   r2   r3   r     s   
zFileInfo.totalr&   c                 C  s   dd t ttj| jD S )Nc                 S  s   i | ]	\}}|t |qS r2   r   )r   r&  valr2   r2   r3   
<dictcomp>  s    z#FileInfo.attrib.<locals>.<dictcomp>)r,   r   r   r(  ry   rY   r2   r2   r3   attrib  r   zFileInfo.attribN)r&  r$   r'  r$   r'   r(   )r'   r	  )r'   r&   )rL   rM   rN   r4   r   r+  r2   r2   r2   r3   r%    s    

r%  c                      sn   e Zd ZU dZd# fdd	Zed
dd edD dZ	de
d< d$ddZed%dd Zd&d!d"Z  ZS )'MemoryXmlReporterz}Internal reporter that generates XML in memory.

    This is used by all other XML-based reporters to avoid duplication.
    rO   r   rP   r$   r'   r(   c                   s~   t  || tj|jdd| _tj|jdd| _tj|jdd| _tj|jdd}t	
t	|| _d | _g | _d S )Nxmlmypy-html.xsltzmypy-txt.xsltmypy-html.csszmypy.xsd)rx   r4   rT   rd   r   r#   xslt_html_pathxslt_txt_pathcss_html_pathr   	XMLSchemaparseschemalast_xmlfiles)r/   rO   rP   xsd_pathrz   r2   r3   r4     s   
zMemoryXmlReporter.__init__ c                 c  s     | ]}|d krt |V  qdS )	   N)chr)r   r   r2   r2   r3   r     s    zMemoryXmlReporter.<genexpr>    z???????????????????????????????r	   control_fixerrA   r   rB   rC   rD   rE   rF   r   c              	   C  sJ  d | _ z	tj|j}W n
 ty   Y d S w t|s!tj|r#d S tjd|j	||dd}|
| tjd||jd}t|}t||j}	t|D ]0\}
}|j|
tj}|	j|  d7  < tj|d| ||
|d| jt|
tj| d qKtjd	|}td
dt| d}|| | j | || _ | j!"|	 d S )NTr   r   rB   r   r   zmypy-report-file)r&  r'  rn   r  r   )any_infocontentnumber	precisionr.  xml-stylesheettype="text/xsl" href="")#r6  rT   rd   relpath
ValueErrorrl   isdirr   r   r   r   r   Elementr   ElementTreer%  rt   r   get
TYPE_EMPTYry   
SubElement_get_any_info_for_linerstrip	translater=  r$   r(  ProcessingInstructionr   addpreviousr5  assertValidr7  r=   )r/   rA   rB   rD   rF   rd   r   rootdoc	file_infolineno	line_textstatus	xslt_pathtransform_pir2   r2   r3   rG     sL   


	
zMemoryXmlReporter.on_filer   stats.StatisticsVisitorrW  r	  c                 C  sl   || j v r4d}t }| j | D ]}||j  d7  < q| D ]\}}|dt|  d| d7 }q |S dS )NzAny Types on this line: rn   r   z (x)zNo Anys on this line!)any_line_mapr   r   type_of_anyr-   r   )r   rW  resultr   r   r   occurrencesr2   r2   r3   rN    s   
z(MemoryXmlReporter._get_any_info_for_linec              
   C  s   d | _ t| jdd d}tjddd}t|}|D ]}tj|d| |jt	|j
t| d qtjd	d
}tddt	| d}|| | j| || _ d S )Nc                 S     | j S r)   r'  r   r2   r2   r3   r   &      z-MemoryXmlReporter.on_finish.<locals>.<lambda>r   zmypy-report-indexindex)r&  r5   )r'  r&  r   r.  .rC  rD  rE  )r6  r,   r7  r   rI  rJ  rM  r+  r'  r   r&  r$   r   rT   rd   rF  rQ  rR  r5  rS  )r/   output_filesrT  rU  rV  rZ  r[  r2   r2   r3   rH   #  s(   



zMemoryXmlReporter.on_finishrZ   rJ   )r   r\  rW  r	  r'   r$   rK   )rL   rM   rN   r  r4   r$   	maketransr   r   r=  __annotations__rG   staticmethodrN  rH   r   r2   r2   rz   r3   r,    s   
 (
4r,  
memory-xml)r?   r  r	  total_linesc                 C  s   |dkrt dS | | dS )Nr   g      ?z.4fr   )r  rl  r2   r2   r3   get_line_rateA  s   rm  c                   @  s.   e Zd ZdZdddZdd	d
ZdddZdS )CoberturaPackagezMContainer for XML and statistics mapping python modules to Cobertura package.r&  r$   r'   r(   c                 C  s"   || _ i | _i | _d| _d| _d S rv   )r&  classespackagesrl  r  )r/   r&  r2   r2   r3   r4   K  s
   
zCoberturaPackage.__init__r   c                 C  sj   t jdd| jd}d|jd< t| j| j|jd< t |d}t| j	D ]
}|
| j	|  q#| | |S )Npackage1.0)
complexityr&  0branch-rate	line-ratero  )r   rI  r&  r+  rm  r  rl  rM  r,   ro  r=   add_packages)r/   package_elementclasses_element
class_namer2   r2   r3   as_xmlR  s   

zCoberturaPackage.as_xmlparent_elementc                 C  sD   | j rt|d}t| j  tddD ]}||  qd S d S )Nrp  r&  r   )rp  r   rM  r,   r   r   r=   r{  )r/   r|  packages_elementrq  r2   r2   r3   rw  \  s   zCoberturaPackage.add_packagesN)r&  r$   r'   r(   )r'   r   )r|  r   r'   r(   )rL   rM   rN   r  r4   r{  rw  r2   r2   r2   r3   rn  H  s
    


rn  c                      r  )CoberturaXmlReporterz0Reporter for generating Cobertura compliant XML.rO   r   rP   r$   r'   r(   c                   sH   t  || tjdttt td| _t	| j| _
td| _d S )Nr   )	timestampversionrf  )rx   r4   r   rI  r$   r	  timer   rT  rJ  rU  rn  root_packagerV   rz   r2   r3   r4   f  s   zCoberturaXmlReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c              	   C  s  t j|j}tjd|j||dd}|| t j|}t||j	}t
jdd||d}	t
|	d t
|	d}
d}d}t|D ]R\}}|j|tj}d}d	}|tjkrVq@|d
7 }|tjkre|d
7 }d
}|tjkrld}|j|  d
7  < t
j|
dt| t|t|tj| d}|rd|jd< q@d|	jd< t|||	jd< |jdd
d }|jdr|j}|| jjvrt|| jj|< | jj| }| j|g}|D ]}| j |7  _ | j!|7  _!q|	|j"|< d S )NTr>  classrr  )rs  r   r&  methodsr   r   Frn   r  )branchhitsrA  rB  z	50% (1/2)zcondition-coveragert  ru  rv  rf  z__init__.py)#rT   rd   rF  r   r   r   r   basenamer%  r   r   rI  rM  rt   r   rK  rL  TYPE_ANYTYPE_IMPRECISEry   r$   lowerr(  r+  rm  r'  rsplitr&  endswithr  rp  rn  rl  r  ro  )r/   rA   rB   rD   rF   rd   r   rz  rV  class_elementlines_elementclass_lines_coveredclass_total_linesrW  r   rY  r  r  line_elementparent_modulecurrent_packagepackages_to_updaterq  r2   r2   r3   rG   m  sj   







zCoberturaXmlReporter.on_filec                 C  s   t | jj| jj| jjd< d| jjd< t| jj| jjd< t| jj| jjd< t| jd}t|d}t	
 |_| j| j t	j| jd}| jj|d	d
d tdt	j| d S )Nrv  rt  ru  zlines-coveredzlines-validsourcesr  zcobertura.xmlutf-8T)encodingpretty_printzGenerated Cobertura report:)rm  r  r  rl  rT  r+  r$   r   rM  rT   getcwdtextrw  rd   r   rP   rU  r   r8   r  )r/   r  source_elementout_pathr2   r2   r3   rH     s   
zCoberturaXmlReporter.on_finishrZ   rJ   rK   r#  r2   r2   rz   r3   r~  c  s
    
Br~  zcobertura-xmlc                      s"   e Zd ZdZd
 fdd	Z  ZS )AbstractXmlReporterz8Internal abstract class for reporters that work via XML.rO   r   rP   r$   r'   r(   c                   s2   t  || |dd}t|tsJ || _d S )Nrk  rQ   )rx   r4   r.   
isinstancer,  
memory_xml)r/   rO   rP   memory_reporterrz   r2   r3   r4     s   
zAbstractXmlReporter.__init__rZ   )rL   rM   rN   r  r4   r   r2   r2   rz   r3   r    s    r  c                   @  s$   e Zd ZdZdddZd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.
    rA   r   rB   rC   rD   rE   rF   r   r'   r(   c                 C  sn   | j j}|d u r
d S tj|j}|drd S tj| jd|d }tjtj	|dd |j
|dd d S )Nre   r-  z.xmlTrR   r  r  )r  r6  rT   rd   rF  ri   r   rP   rU   dirnamer   )r/   rA   rB   rD   rF   r6  rd   r  r2   r2   r3   rG     s   
zXmlReporter.on_filec                 C  s   | j j}|d us
J tj| jd}tj| jd}tj| jd}|j|dd t| j j	| t| j j
| tdtj| d S )Nz	index.xmlr.  r/  r  r  zGenerated XML report:)r  r6  rT   rd   r   rP   r   shutilcopyfiler0  r2  r8   r  )r/   r6  r  out_xsltout_cssr2   r2   r3   rH     s   zXmlReporter.on_finishNrJ   rK   )rL   rM   rN   r  rG   rH   r2   r2   r2   r3   r    s    
	r  r-  c                      r  )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.
    rO   r   rP   r$   r'   r(   c                   s6   t  || tt| jj| _tjd| _	d S )Nhtml)
rx   r4   r   XSLTr4  r  r0  	xslt_htmlstrparam
param_htmlrV   rz   r2   r3   r4     s   zXsltHtmlReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c           
      C  s   | j j}|d u r
d S tj|j}|drd S tj| jd|d }tjtj	|dd t
| j|| jd}t|d}	|	| W d    d S 1 sNw   Y  d S )Nre   r  z.htmlTrR   extwb)r  r6  rT   rd   rF  ri   r   rP   rU   r  bytesr  r  rp   r   )
r/   rA   rB   rD   rF   r6  rd   r  transformed_htmlout_filer2   r2   r3   rG     s   
"zXsltHtmlReporter.on_filec                 C  s   | j j}|d us
J tj| jd}tj| jd}t| j|| jd}t	|d}|
| W d    n1 s9w   Y  t| j j| tdtj| d S )Nz
index.htmlr/  r  r  z!Generated HTML report (via XSLT):)r  r6  rT   rd   r   rP   r  r  r  rp   r   r  r  r2  r8   r  )r/   r6  r  r  r  r  r2   r2   r3   rH     s   zXsltHtmlReporter.on_finishrZ   rJ   rK   r#  r2   r2   rz   r3   r    s
    
r  z	xslt-htmlc                      r  )XsltTxtReporterzvPublic reporter that exports TXT via XSLT.

    Currently this only does the summary, not the individual reports.
    rO   r   rP   r$   r'   r(   c                   s(   t  || tt| jj| _d S r)   )rx   r4   r   r  r4  r  r1  xslt_txtrV   rz   r2   r3   r4   -  s   zXsltTxtReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c                 C  rW   r)   r2   rX   r2   r2   r3   rG   2  s   zXsltTxtReporter.on_filec                 C  s|   | j j}|d us
J tj| jd}t| |}t|d}|	| W d    n1 s.w   Y  t
dtj| d S )Nz	index.txtr  z Generated TXT report (via XSLT):)r  r6  rT   rd   r   rP   r  r  rp   r   r8   r  )r/   r6  r  transformed_txtr  r2   r2   r3   rH   ;  s   zXsltTxtReporter.on_finishrZ   rJ   rK   r#  r2   r2   rz   r3   r  '  s
    
	r  zxslt-txtr  txtc                      r  )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.
    rO   r   rP   r$   r'   r(   c                   s   t  || g | _d S r)   )rx   r4   r7  rV   rz   r2   r3   r4   Z  r   zLinePrecisionReporter.__init__rA   r   rB   rC   rD   rE   rF   r   c                 C  s   z	t j|j}W n
 ty   Y d S w t|rd S tjd|j||dd}|| t	||j
}t|D ]\}}	|j|tj}
|j|
  d7  < q4| j| d S )NTr>  rn   )rT   rd   rF  rG  rl   r   r   r   r   r%  r   rt   r   rK  rL  ry   r7  r=   )r/   rA   rB   rD   rF   rd   r   rV  rW  r   rY  r2   r2   r3   rG   ^  s(   
zLinePrecisionReporter.on_filec           
      C  s  | j sd S t| j dd d}tj| jd}tdtdd |D }d}|ftd	d |D  }d
| }t|dK}|	|j
dg|R   |	d|d  d  |D ](}|j}	|	|
|j|| |	tj |	tj |	tj |	tj |	tj  qSW d    d S 1 sw   Y  d S )Nc                 S  rb  r)   rc  r   r2   r2   r3   r     rd  z1LinePrecisionReporter.on_finish.<locals>.<lambda>r   zlineprecision.txtr   c                 s  s    | ]}t |jV  qd S r)   )r   r'  )r   infor2   r2   r3   r     s    z2LinePrecisionReporter.on_finish.<locals>.<genexpr>)LinesPrecise	Impreciser   Empty
Unanalyzedc                 s  s    | ]}t |V  qd S r)   r   )r   tr2   r2   r3   r     r   z0{:%d}  {:%d}  {:%d}  {:%d}  {:%d}  {:%d}  {:%d}
r   r   r   3   r   )r7  r,   rT   rd   r   rP   r   r   rp   r   r9   ry   r'  ljustr   r   TYPE_PRECISEr  r  rL  r   )
r/   rg  report_filewidthtitlesr   fmtr   rV  ry   r2   r2   r3   rH   }  s4   
"zLinePrecisionReporter.on_finishrZ   rJ   rK   r#  r2   r2   rz   r3   r  K  s
    
r  lineprecision)F)r\   r$   r@   r]   r?   r^   r'   r(   )ra   r$   rb   r$   r'   r(   )rd   r$   r'   r^   )rd   r$   r'   rm   )r  r	  rl  r	  r'   r$   )Ur  
__future__r   r   r   r!  rT   r  r:   r  ro   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   r7   r<   OrderedDictunannotatedexplicitfrom_unimported_typefrom_omitted_generics
from_errorspecial_formimplementation_artifactr   ri  r$   r^   r!   r"   r   r   r`   rc   rl   rt   ru   r   r   r  r  r%  r,  rm  rn  r~  r  r  r  r  r  setr2   r2   r2   r3   <module>   s     -




	
4
`[
'r
\',


N