Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stubtest: catch BaseException on imports #14284

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Changes from 2 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
11 changes: 8 additions & 3 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def test_module(module_name: str) -> Iterator[Error]:

try:
runtime = silent_import_module(module_name)
except Exception as e:
except KeyboardInterrupt:
raise
except BaseException as e:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
yield Error([module_name], f"failed to import, {type(e).__name__}: {e}", stub, MISSING)
return

Expand Down Expand Up @@ -1495,13 +1497,16 @@ def build_stubs(modules: list[str], options: Options, find_submodules: bool = Fa
# find submodules via pkgutil
try:
runtime = silent_import_module(module)
except KeyboardInterrupt:
raise
except BaseException:
pass
else:
all_modules.extend(
m.name
for m in pkgutil.walk_packages(runtime.__path__, runtime.__name__ + ".")
if m.name not in all_modules
)
except Exception:
pass

if sources:
try:
Expand Down