Skip to content

Commit ceaf48d

Browse files
authoredDec 21, 2024··
Print InspectError traceback in stubgen walk_packages when verbose is specified (#18224)
This change modifies `walk_packages` such that the full `ImporError` traceback is printed when a module cannot be imported. The goal is to provide the user with more context to debug the error. I implemented this change by mirroring existing behavior in `find_module_paths_using_imports`: https://github.com/python/mypy/blob/9405bfd9205ea369c11150907764fa46c03cb1f7/mypy/stubgen.py#L1522-L1529
1 parent 924f818 commit ceaf48d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎mypy/stubgen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ def find_module_paths_using_imports(
15241524
except CantImport as e:
15251525
tb = traceback.format_exc()
15261526
if verbose:
1527-
sys.stdout.write(tb)
1527+
sys.stderr.write(tb)
15281528
if not quiet:
15291529
report_missing(mod, e.message, tb)
15301530
continue

‎mypy/stubutil.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os.path
66
import re
77
import sys
8+
import traceback
89
from abc import abstractmethod
910
from collections import defaultdict
1011
from contextlib import contextmanager
@@ -70,6 +71,9 @@ def walk_packages(
7071
try:
7172
prop = inspect.get_package_properties(package_name)
7273
except InspectError:
74+
if verbose:
75+
tb = traceback.format_exc()
76+
sys.stderr.write(tb)
7377
report_missing(package_name)
7478
continue
7579
yield prop.name

0 commit comments

Comments
 (0)
Please sign in to comment.