Skip to content

Commit 7ffbc53

Browse files
AFanaeiJukkaL
authored andcommitted
Record special Any as precise in report generation (#7708)
Fixes #6784.
1 parent 270afec commit 7ffbc53

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

mypy/stats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def type(self, t: Optional[Type]) -> None:
332332
return
333333

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

338339
if isinstance(t, AnyType):

test-data/unit/reports.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,39 @@ async def some_function(x) -> None:
422422
l 1 0 0 0 0 0 0
423423
-----------------------------------------------------------------------------------------------------------------
424424
Total 1 1 0 0 0 0 0
425+
426+
[case testSpecialAnyHtmlReport]
427+
# cmd: mypy --html-report report n.py
428+
[file n.py]
429+
from typing import Callable
430+
431+
SourceToDisplay = Callable[[int], int]
432+
DisplayToSource = Callable[[int], int]
433+
434+
[file report/mypy-html.css]
435+
[file report/index.html]
436+
[outfile report/html/n.py.html]
437+
<html>
438+
<head>
439+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
440+
<link rel="stylesheet" type="text/css" href="../mypy-html.css">
441+
</head>
442+
<body>
443+
<h2>n</h2>
444+
<table>
445+
<caption>n.py</caption>
446+
<tbody><tr>
447+
<td class="table-lines"><pre><span id="L1" class="lineno"><a class="lineno" href="#L1">1</a></span>
448+
<span id="L2" class="lineno"><a class="lineno" href="#L2">2</a></span>
449+
<span id="L3" class="lineno"><a class="lineno" href="#L3">3</a></span>
450+
<span id="L4" class="lineno"><a class="lineno" href="#L4">4</a></span>
451+
</pre></td>
452+
<td class="table-code"><pre><span class="line-precise" title="No Anys on this line!">from typing import Callable</span>
453+
<span class="line-empty" title="No Anys on this line!"></span>
454+
<span class="line-precise" title="No Anys on this line!">SourceToDisplay = Callable[[int], int]</span>
455+
<span class="line-precise" title="No Anys on this line!">DisplayToSource = Callable[[int], int]</span>
456+
</pre></td>
457+
</tr></tbody>
458+
</table>
459+
</body>
460+
</html>

0 commit comments

Comments
 (0)