mypy-htmlreport-isadirectoryerror

Example repo for python/mypy#11334

Preparation

$ poetry install --no-root

Repro

A. Mypy works fine with -p and without --html-report:

$ poetry run mypy -p folder
Success: no issues found in 4 source files

B. Mypy works fine with --html-report and without -p:

$ poetry run mypy folder --html-report=mypy-report
Generated HTML report (via XSLT): /mnt/c/tmp/mypy-bug/mypy-report/index.html
Success: no issues found in 3 source files
Note

In the real repo I cannot omit -p because of errors mypy reports in local namespace packages:

ldap_tool/commands/fetch_users.py:10: error: Skipping analyzing ".base": found module but no type hints or library stubs

C. Mypy breaks when passed both -p and --html-report:

$ poetry run mypy -p folder --html-report=mypy-report
/mnt/c/tmp/mypy-bug/folder/subfolder: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
If this issue continues with mypy master, please report a bug at https://github.com/python/mypy/issues
version: 0.910
/mnt/c/tmp/mypy-bug/folder/subfolder: : note: please use --show-traceback to print a traceback when reporting a bug
Generated HTML report (via XSLT): /mnt/c/tmp/mypy-bug/mypy-report/index.html
$ poetry run mypy -p folder --html-report=mypy-report --show-traceback
/mnt/c/tmp/mypy-bug/folder/subfolder: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.910
Traceback (most recent call last):
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "mypy/build.py", line 1955, in wrap_context
  File "mypy/build.py", line 2205, in finish_passes
  File "mypy/build.py", line 818, in report_file
  File "mypy/report.py", line 83, in file
  File "mypy/report.py", line 482, in on_file
  File "mypy/report.py", line 131, in iterate_python_lines
  File "/usr/lib/python3.8/tokenize.py", line 392, in open
    buffer = _builtin_open(filename, 'rb')
IsADirectoryError: [Errno 21] Is a directory: 'folder/subfolder'
/mnt/c/tmp/mypy-bug/folder/subfolder: : note: use --pdb to drop into pdb
Generated HTML report (via XSLT): /mnt/c/tmp/mypy-bug/mypy-report/index.html

Reproducible with mypy@master as well:

$ poetry run mypy -p folder --html-report=mypy-report --show-traceback
/mnt/c/tmp/mypy-bug/folder/subfolder: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.920+dev.a114826deea730baf8b618207d579805f1149ea0
Traceback (most recent call last):
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/main.py", line 87, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/main.py", line 165, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 179, in build
    result = _build(
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 254, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 2710, in dispatch
    process_graph(graph, manager)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 3041, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 3142, in process_stale_scc
    graph[id].finish_passes()
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 2223, in finish_passes
    free_tree(self.tree)
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 1962, in wrap_context
    yield
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 2218, in finish_passes
    manager.report_file(self.tree, self.type_map(), self.options)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/build.py", line 821, in report_file
    self.reports.file(file, self.modules, type_map, options)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/report.py", line 88, in file
    reporter.on_file(tree, modules, type_map, options)
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/report.py", line 486, in on_file
    for lineno, line_text in iterate_python_lines(path):
  File "/home/user/.cache/pypoetry/virtualenvs/mypy-bug-3PnpPrM--py3.8/lib/python3.8/site-packages/mypy/report.py", line 136, in iterate_python_lines
    with tokenize.open(path) as input_file:
  File "/usr/lib/python3.8/tokenize.py", line 392, in open
    buffer = _builtin_open(filename, 'rb')
IsADirectoryError: [Errno 21] Is a directory: 'folder/subfolder'
/mnt/c/tmp/mypy-bug/folder/subfolder: : note: use --pdb to drop into pdb
Generated HTML report (via XSLT): /mnt/c/tmp/mypy-bug/mypy-report/index.html