@@ -285,12 +285,18 @@ def __init__(self, reports: Reports, output_dir: str) -> None:
285
285
super ().__init__ (reports , output_dir )
286
286
287
287
self .xslt_html_path = os .path .join (reports .data_dir , 'xml' , 'mypy-html.xslt' )
288
+ self .xslt_html_tooltips_path = os .path .join (
289
+ reports .data_dir , 'xml' , 'mypy-html-tooltips.xslt' )
288
290
self .xslt_txt_path = os .path .join (reports .data_dir , 'xml' , 'mypy-txt.xslt' )
289
291
self .css_html_path = os .path .join (reports .data_dir , 'xml' , 'mypy-html.css' )
290
292
xsd_path = os .path .join (reports .data_dir , 'xml' , 'mypy.xsd' )
291
293
self .schema = etree .XMLSchema (etree .parse (xsd_path ))
292
294
self .last_xml = None # type: etree._ElementTree
293
295
self .files = [] # type: List[FileInfo]
296
+ self .type_columns = False
297
+
298
+ def set_type_columns (self , type_columns : bool ) -> None :
299
+ self .type_columns = type_columns
294
300
295
301
def on_file (self , tree : MypyFile , type_map : Dict [Expression , Type ]) -> None :
296
302
self .last_xml = None
@@ -302,7 +308,8 @@ def on_file(self, tree: MypyFile, type_map: Dict[Expression, Type]) -> None:
302
308
if 'stubs' in path .split ('/' ):
303
309
return
304
310
305
- visitor = stats .StatisticsVisitor (inferred = True , typemap = type_map , all_nodes = True )
311
+ visitor = stats .StatisticsVisitor (inferred = True , typemap = type_map , all_nodes = True ,
312
+ linecol_typestr = self .type_columns )
306
313
tree .accept (visitor )
307
314
308
315
root = etree .Element ('mypy-report-file' , name = path , module = tree ._fullname )
@@ -313,10 +320,28 @@ def on_file(self, tree: MypyFile, type_map: Dict[Expression, Type]) -> None:
313
320
for lineno , line_text in enumerate (input_file , 1 ):
314
321
status = visitor .line_map .get (lineno , stats .TYPE_EMPTY )
315
322
file_info .counts [status ] += 1
316
- etree .SubElement (root , 'line' ,
323
+ line = etree .SubElement (root , 'line' ,
317
324
number = str (lineno ),
318
325
precision = stats .precision_names [status ],
319
326
content = line_text [:- 1 ])
327
+
328
+ if self .type_columns :
329
+ for column , ch in enumerate (line_text [:- 1 ]):
330
+ if lineno in visitor .linecol_typename_map :
331
+ row = visitor .linecol_typename_map [lineno ]
332
+ if column in row :
333
+ typestr = row [column ]
334
+ else :
335
+ typestr = ""
336
+ else :
337
+ typestr = ""
338
+
339
+ etree .SubElement (line ,
340
+ "char" ,
341
+ column = str (column ),
342
+ typestr = typestr ,
343
+ content = ch )
344
+
320
345
# Assumes a layout similar to what XmlReporter uses.
321
346
xslt_path = os .path .relpath ('mypy-html.xslt' , path )
322
347
transform_pi = etree .ProcessingInstruction ('xml-stylesheet' ,
@@ -530,9 +555,12 @@ class XsltHtmlReporter(AbstractXmlReporter):
530
555
def __init__ (self , reports : Reports , output_dir : str ) -> None :
531
556
super ().__init__ (reports , output_dir )
532
557
533
- self .xslt_html = etree .XSLT (etree .parse (self .memory_xml . xslt_html_path ))
558
+ self .xslt_html = etree .XSLT (etree .parse (self .xslt_file_to_use () ))
534
559
self .param_html = etree .XSLT .strparam ('html' )
535
560
561
+ def xslt_file_to_use (self ) -> str :
562
+ return self .memory_xml .xslt_html_path
563
+
536
564
def on_file (self , tree : MypyFile , type_map : Dict [Expression , Type ]) -> None :
537
565
last_xml = self .memory_xml .last_xml
538
566
if last_xml is None :
@@ -560,6 +588,19 @@ def on_finish(self) -> None:
560
588
register_reporter ('xslt-html' , XsltHtmlReporter , needs_lxml = True )
561
589
562
590
591
+ class XsltHtmlTooltipsReporter (XsltHtmlReporter ):
592
+ def __init__ (self , reports : Reports , output_dir : str ) -> None :
593
+ super ().__init__ (reports , output_dir )
594
+ self .memory_xml .set_type_columns (True )
595
+
596
+ def xslt_file_to_use (self ) -> str :
597
+ return self .memory_xml .xslt_html_tooltips_path
598
+
599
+
600
+ register_reporter ('xslt-html-tooltips' ,
601
+ XsltHtmlTooltipsReporter , needs_lxml = True )
602
+
603
+
563
604
class XsltTxtReporter (AbstractXmlReporter ):
564
605
"""Public reporter that exports TXT via XSLT.
565
606
0 commit comments