Closed
Description
Bug Report
I'm having an issue running mypy on a package with the -p
argument where the package directory has a subdirectory inside it. I'm receiving the following error with mypy 0.9.10:
Traceback (most recent call last):
File "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/__main__.py", line 23, in <module>
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 "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/tokenize.py", line 392, in open
buffer = _builtin_open(filename, 'rb')
IsADirectoryError: [Errno 21] Is a directory: 'python_tools/resources'
I tested with the master branch, and the error is the same, but the traceback is different:
Traceback (most recent call last):
File "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/__main__.py", line 23, in <module>
console_entry()
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/main.py", line 87, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/Users/oleksiyk/virtualenv_python38/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 "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 179, in build
result = _build(
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 254, in _build
graph = dispatch(sources, manager, stdout)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 2707, in dispatch
process_graph(graph, manager)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 3031, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 3132, in process_stale_scc
graph[id].finish_passes()
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 2220, in finish_passes
free_tree(self.tree)
File "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 1962, in wrap_context
yield
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 2215, in finish_passes
manager.report_file(self.tree, self.type_map(), self.options)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/build.py", line 821, in report_file
self.reports.file(file, self.modules, type_map, options)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/report.py", line 85, in file
reporter.on_file(tree, modules, type_map, options)
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/report.py", line 483, in on_file
for lineno, line_text in iterate_python_lines(path):
File "/Users/oleksiyk/virtualenv_python38/lib/python3.8/site-packages/mypy/report.py", line 133, in iterate_python_lines
with tokenize.open(path) as input_file:
File "/Users/oleksiyk/.pyenv/versions/3.8.9/lib/python3.8/tokenize.py", line 392, in open
buffer = _builtin_open(filename, 'rb')
IsADirectoryError: [Errno 21] Is a directory: 'python_tools/resources'
Without the -p argument, the command passes with no issue.
Expected Behavior
I'm not too familiar with mypy, but I would expect the code to ignore such directories I think. I'm also not sure why the -p argument would cause this issue, when the code otherwise works normally. When I dug through the traceback a bit, I found this function
Lines 121 to 128 in f98f782
resources
to stubs
, and that fixed the error. Perhaps all directories should be ignored by this skip function (or maybe they shouldn't be passed into it in the first place, not sure)?
My Environment
- Mypy version used: 0.9.10 and 0.920+dev.209a7193feb4bbfa38d09232b0a5a916e9d2e605
- Full command run:
python3.8 -m mypy --txt-report ~/tmp/mypyr_report --install-types --non-interactive --namespace-packages --ignore-missing-imports -p yahoo.contrib.mx3_python_tools --show-traceback
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.8.9 (although in a separate env, 3.9 showed the same issue)
- Operating system and version: MacOS Big Sur version 11.6