Skip to content

Commit

Permalink
Linters are silly
Browse files Browse the repository at this point in the history
  • Loading branch information
o11c committed Oct 10, 2015
1 parent 4cde813 commit 2834a43
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
16 changes: 9 additions & 7 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self) -> None:
self.build_flags = [] # type: List[str]
self.pyversion = 3
self.custom_typing_module = None # type: str
self.report_dirs = {} # type: Dict[str, str]
self.report_dirs = {} # type: Dict[str, str]
self.python_path = False


Expand Down Expand Up @@ -152,20 +152,22 @@ def process_options(args: List[str]) -> Tuple[str, str, str, Options]:

# Don't generate this from mypy.reports, not all are meant to be public.
REPORTS = [
'html',
'old-html',
'xslt-html',
'xml',
'txt',
'xslt-txt',
'html',
'old-html',
'xslt-html',
'xml',
'txt',
'xslt-txt',
]


def is_report(arg: str) -> bool:
if arg.startswith('--') and arg.endswith('-report'):
report_type = arg[2:-7]
return report_type in REPORTS
return False


def usage(msg: str = None) -> None:
if msg:
sys.stderr.write('%s\n' % msg)
Expand Down
25 changes: 17 additions & 8 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from mypy import stats


reporter_classes = {} # type: Dict[str, Callable[[Reports, str], AbstractReporter]]
reporter_classes = {} # type: Dict[str, Callable[[Reports, str], AbstractReporter]]


class Reports:
def __init__(self, main_file: str, data_dir: str, report_dirs: Dict[str, str]) -> None:
self.main_file = main_file
self.data_dir = data_dir
self.reporters = [] # type: List[AbstractReporter]
self.named_reporters = {} # type: Dict[str, AbstractReporter]
self.reporters = [] # type: List[AbstractReporter]
self.named_reporters = {} # type: Dict[str, AbstractReporter]

for report_type, report_dir in sorted(report_dirs.items()):
self.add_report(report_type, report_dir)
Expand Down Expand Up @@ -57,6 +57,7 @@ def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None:
def on_finish(self) -> None:
pass


class OldHtmlReporter(AbstractReporter):
"""Old HTML reporter.
Expand All @@ -71,6 +72,7 @@ def on_finish(self) -> None:
stats.generate_html_index(self.output_dir)
reporter_classes['old-html'] = OldHtmlReporter


class FileInfo:
def __init__(self, name: str, module: str) -> None:
self.name = name
Expand All @@ -83,6 +85,7 @@ def total(self) -> int:
def attrib(self) -> Dict[str, str]:
return {name: str(val) for name, val in zip(stats.precision_names, self.counts)}


class MemoryXmlReporter(AbstractReporter):
"""Internal reporter that generates XML in memory.
Expand All @@ -100,8 +103,8 @@ def __init__(self, reports: Reports, output_dir: str) -> None:
self.css_html_path = os.path.join(reports.data_dir, 'xml', 'mypy-html.css')
xsd_path = os.path.join(reports.data_dir, 'xml', 'mypy.xsd')
self.schema = etree.XMLSchema(etree.parse(xsd_path))
self.last_xml = None # type: etree._ElementTree
self.files = [] # type: List[FileInfo]
self.last_xml = None # type: etree._ElementTree
self.files = [] # type: List[FileInfo]

def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None:
import lxml.etree as etree
Expand Down Expand Up @@ -133,7 +136,8 @@ def on_file(self, tree: MypyFile, type_map: Dict[Node, Type]) -> None:
# Assumes a layout similar to what XmlReporter uses.
xslt_path = os.path.relpath('mypy-html.xslt', path)
xml_pi = etree.ProcessingInstruction('xml', 'version="1.0" encoding="utf-8"')
transform_pi = etree.ProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="%s"' % cgi.escape(xslt_path, True))
transform_pi = etree.ProcessingInstruction('xml-stylesheet',
'type="text/xsl" href="%s"' % cgi.escape(xslt_path, True))
root.addprevious(xml_pi)
root.addprevious(transform_pi)
self.schema.assertValid(doc)
Expand All @@ -145,7 +149,7 @@ def on_finish(self) -> None:
import lxml.etree as etree

self.last_xml = None
index_path = os.path.join(self.output_dir, 'index.xml')
# index_path = os.path.join(self.output_dir, 'index.xml')
output_files = sorted(self.files, key=lambda x: x.module)

root = etree.Element('mypy-report-index', name=self.main_file)
Expand All @@ -159,7 +163,8 @@ def on_finish(self) -> None:
module=file_info.module)
xslt_path = os.path.relpath('mypy-html.xslt', '.')
xml_pi = etree.ProcessingInstruction('xml', 'version="1.0" encoding="utf-8"')
transform_pi = etree.ProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="%s"' % cgi.escape(xslt_path, True))
transform_pi = etree.ProcessingInstruction('xml-stylesheet',
'type="text/xsl" href="%s"' % cgi.escape(xslt_path, True))
root.addprevious(xml_pi)
root.addprevious(transform_pi)
self.schema.assertValid(doc)
Expand All @@ -168,6 +173,7 @@ def on_finish(self) -> None:

reporter_classes['memory-xml'] = MemoryXmlReporter


class AbstractXmlReporter(AbstractReporter):
"""Internal abstract class for reporters that work via XML."""

Expand All @@ -178,6 +184,7 @@ def __init__(self, reports: Reports, output_dir: str) -> None:
# The dependency will be called first.
self.memory_xml = cast(MemoryXmlReporter, memory_reporter)


class XmlReporter(AbstractXmlReporter):
"""Public reporter that exports XML.
Expand Down Expand Up @@ -211,6 +218,7 @@ def on_finish(self) -> None:

reporter_classes['xml'] = XmlReporter


class XsltHtmlReporter(AbstractXmlReporter):
"""Public reporter that exports HTML via XSLT.
Expand Down Expand Up @@ -251,6 +259,7 @@ def on_finish(self) -> None:

reporter_classes['xslt-html'] = XsltHtmlReporter


class XsltTxtReporter(AbstractXmlReporter):
"""Public reporter that exports TXT via XSLT.
Expand Down
8 changes: 4 additions & 4 deletions mypy/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
TYPE_ANY = 3

precision_names = [
'empty',
'precise',
'imprecise',
'any',
'empty',
'precise',
'imprecise',
'any',
]


Expand Down

0 comments on commit 2834a43

Please sign in to comment.