Skip to content

Commit

Permalink
Record special Any as precise in report generation (python#7708)
Browse files Browse the repository at this point in the history
  • Loading branch information
AFanaei authored and JukkaL committed Oct 30, 2019
1 parent 270afec commit 7ffbc53
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ def type(self, t: Optional[Type]) -> None:
return

if isinstance(t, AnyType) and is_special_form_any(t):
# This is not a real Any type, so don't collect stats for it.
# TODO: What if there is an error in special form definition?
self.record_line(self.line, TYPE_PRECISE)
return

if isinstance(t, AnyType):
Expand Down
36 changes: 36 additions & 0 deletions test-data/unit/reports.test
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,39 @@ async def some_function(x) -> None:
l 1 0 0 0 0 0 0
-----------------------------------------------------------------------------------------------------------------
Total 1 1 0 0 0 0 0

[case testSpecialAnyHtmlReport]
# cmd: mypy --html-report report n.py
[file n.py]
from typing import Callable

SourceToDisplay = Callable[[int], int]
DisplayToSource = Callable[[int], int]

[file report/mypy-html.css]
[file report/index.html]
[outfile report/html/n.py.html]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
</head>
<body>
<h2>n</h2>
<table>
<caption>n.py</caption>
<tbody><tr>
<td class="table-lines"><pre><span id="L1" class="lineno"><a class="lineno" href="#L1">1</a></span>
<span id="L2" class="lineno"><a class="lineno" href="#L2">2</a></span>
<span id="L3" class="lineno"><a class="lineno" href="#L3">3</a></span>
<span id="L4" class="lineno"><a class="lineno" href="#L4">4</a></span>
</pre></td>
<td class="table-code"><pre><span class="line-precise" title="No Anys on this line!">from typing import Callable</span>
<span class="line-empty" title="No Anys on this line!"></span>
<span class="line-precise" title="No Anys on this line!">SourceToDisplay = Callable[[int], int]</span>
<span class="line-precise" title="No Anys on this line!">DisplayToSource = Callable[[int], int]</span>
</pre></td>
</tr></tbody>
</table>
</body>
</html>

0 comments on commit 7ffbc53

Please sign in to comment.