Skip to content

Commit 6cafa35

Browse files
committed
Merge pull request #710 from o11c/html-report-bug
Fix bad html report bug
2 parents adf5422 + 764de05 commit 6cafa35

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

mypy/stats.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,19 @@ def generate_html_report(tree: Node, path: str, type_map: Dict[Node, Type],
261261
output_dir: str) -> None:
262262
if is_special_module(path):
263263
return
264+
# There may be more than one right answer for "what should we do here?"
265+
# but this is a reasonable one.
266+
path = os.path.relpath(path)
267+
if path.startswith('..'):
268+
return
264269
visitor = StatisticsVisitor(inferred=True, typemap=type_map, all_nodes=True)
265270
tree.accept(visitor)
271+
assert not os.path.isabs(path) and not path.startswith('..')
272+
# This line is *wrong* if the preceding assert fails.
266273
target_path = os.path.join(output_dir, 'html', path)
267-
target_path = re.sub(r'\.py$', '.html', target_path)
274+
# replace .py or .pyi with .html
275+
target_path = os.path.splitext(target_path)[0] + '.html'
276+
assert target_path.endswith('.html')
268277
ensure_dir_exists(os.path.dirname(target_path))
269278
output = [] # type: List[str]
270279
append = output.append

0 commit comments

Comments
 (0)