MCPcopy Create free account
hub / github.com/python/mypy / on_file

Method on_file

mypy/report.py:486–536  ·  view source on GitHub ↗
(
        self,
        tree: MypyFile,
        modules: dict[str, MypyFile],
        type_map: dict[Expression, Type],
        options: Options,
    )

Source from the content-addressed store, hash-verified

484 control_fixer: Final = str.maketrans("".join(chr(i) for i in range(32) if i != 9), "?" * 31)
485
486 def on_file(
487 self,
488 tree: MypyFile,
489 modules: dict[str, MypyFile],
490 type_map: dict[Expression, Type],
491 options: Options,
492 ) -> None:
493 self.last_xml = None
494
495 try:
496 path = os.path.relpath(tree.path)
497 except ValueError:
498 return
499
500 if should_skip_path(path) or os.path.isdir(path):
501 return # `path` can sometimes be a directory, see #11334
502
503 visitor = stats.StatisticsVisitor(
504 inferred=True,
505 filename=tree.fullname,
506 modules=modules,
507 typemap=type_map,
508 all_nodes=True,
509 )
510 tree.accept(visitor)
511
512 root = etree.Element("mypy-report-file", name=path, module=tree._fullname)
513 doc = etree.ElementTree(root)
514 file_info = FileInfo(path, tree._fullname)
515
516 for lineno, line_text in iterate_python_lines(path):
517 status = visitor.line_map.get(lineno, stats.TYPE_EMPTY)
518 file_info.counts[status] += 1
519 etree.SubElement(
520 root,
521 "line",
522 any_info=self._get_any_info_for_line(visitor, lineno),
523 content=line_text.rstrip("\n").translate(self.control_fixer),
524 number=str(lineno),
525 precision=stats.precision_names[status],
526 )
527 # Assumes a layout similar to what XmlReporter uses.
528 xslt_path = os.path.relpath("mypy-html.xslt", path)
529 transform_pi = etree.ProcessingInstruction(
530 "xml-stylesheet", f'type="text/xsl" href="{pathname2url(xslt_path)}"'
531 )
532 root.addprevious(transform_pi)
533 self.schema.assertValid(doc)
534
535 self.last_xml = doc
536 self.files.append(file_info)
537
538 @staticmethod
539 def _get_any_info_for_line(visitor: stats.StatisticsVisitor, lineno: int) -> str:

Callers

nothing calls this directly

Calls 11

should_skip_pathFunction · 0.85
FileInfoClass · 0.85
iterate_python_linesFunction · 0.85
strClass · 0.85
translateMethod · 0.80
rstripMethod · 0.80
appendMethod · 0.80
isdirMethod · 0.45
acceptMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected