Skip to content

Commit 33717e5

Browse files
Better error for mypy -p package without py.typed (#17908)
Improve the error message when running `mypy -p packagename` with a package that doesn't have py.typed set. > package 'example' is skipping due to missing py.typed marker. See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details Fix #17048 --------- Co-authored-by: Shantanu <[email protected]>
1 parent eca206d commit 33717e5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

mypy/main.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
from mypy.errors import CompileError
2323
from mypy.find_sources import InvalidSourceList, create_source_list
2424
from mypy.fscache import FileSystemCache
25-
from mypy.modulefinder import BuildSource, FindModuleCache, SearchPaths, get_search_dirs, mypy_path
25+
from mypy.modulefinder import (
26+
BuildSource,
27+
FindModuleCache,
28+
ModuleNotFoundReason,
29+
SearchPaths,
30+
get_search_dirs,
31+
mypy_path,
32+
)
2633
from mypy.options import INCOMPLETE_FEATURES, BuildType, Options
2734
from mypy.split_namespace import SplitNamespace
2835
from mypy.version import __version__
@@ -1413,7 +1420,15 @@ def set_strict_flags() -> None:
14131420
fail(f"Package name '{p}' cannot have a slash in it.", stderr, options)
14141421
p_targets = cache.find_modules_recursive(p)
14151422
if not p_targets:
1416-
fail(f"Can't find package '{p}'", stderr, options)
1423+
reason = cache.find_module(p)
1424+
if reason is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
1425+
fail(
1426+
f"Package '{p}' cannot be type checked due to missing py.typed marker. See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details",
1427+
stderr,
1428+
options,
1429+
)
1430+
else:
1431+
fail(f"Can't find package '{p}'", stderr, options)
14171432
targets.extend(p_targets)
14181433
for m in special_opts.modules:
14191434
targets.append(BuildSource(None, m, None))

0 commit comments

Comments
 (0)