Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,9 @@ def should_skip_path(path: str) -> bool:

def iterate_python_lines(path: str) -> Iterator[tuple[int, str]]:
"""Return an iterator over (line number, line text) from a Python file."""
try:
if not os.path.isdir(path): # can happen with namespace packages
with tokenize.open(path) as input_file:
yield from enumerate(input_file, 1)
except IsADirectoryError:
# can happen with namespace packages
pass


class FuncCounterVisitor(TraverserVisitor):
Expand Down
34 changes: 34 additions & 0 deletions test-data/unit/reports.test
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,37 @@ namespace_packages = True
</table>
</body>
</html>

[case testReportCoberturaCrashOnNamespacePackages]
# cmd: mypy --cobertura-xml-report report -p folder
-- Regression test for https://github.com/python/mypy/issues/19843
[file folder/subfolder/something.py]
-- This output is not important, but due to the way tests are run we need to check it.
[outfile report/cobertura.xml]
<coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="1.0" branch-rate="0" lines-covered="0" lines-valid="0">
<sources>
<source>$PWD</source>
</sources>
<packages>
<package complexity="1.0" name="folder" branch-rate="0" line-rate="1.0">
<classes>
<class complexity="1.0" filename="folder" name="folder" branch-rate="0" line-rate="1.0">
<methods/>
<lines/>
</class>
<class complexity="1.0" filename="folder/subfolder" name="subfolder" branch-rate="0" line-rate="1.0">
<methods/>
<lines/>
</class>
</classes>
</package>
<package complexity="1.0" name="folder.subfolder" branch-rate="0" line-rate="1.0">
<classes>
<class complexity="1.0" filename="folder/subfolder/something.py" name="something.py" branch-rate="0" line-rate="1.0">
<methods/>
<lines/>
</class>
</classes>
</package>
</packages>
</coverage>