Skip to content

Commit

Permalink
Better error for mypy -p package without py.typed (python#17908)
Browse files Browse the repository at this point in the history
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 python#17048

---------

Co-authored-by: Shantanu <[email protected]>
  • Loading branch information
jogo-openai and hauntsaninja authored Oct 10, 2024
1 parent eca206d commit 33717e5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
from mypy.errors import CompileError
from mypy.find_sources import InvalidSourceList, create_source_list
from mypy.fscache import FileSystemCache
from mypy.modulefinder import BuildSource, FindModuleCache, SearchPaths, get_search_dirs, mypy_path
from mypy.modulefinder import (
BuildSource,
FindModuleCache,
ModuleNotFoundReason,
SearchPaths,
get_search_dirs,
mypy_path,
)
from mypy.options import INCOMPLETE_FEATURES, BuildType, Options
from mypy.split_namespace import SplitNamespace
from mypy.version import __version__
Expand Down Expand Up @@ -1413,7 +1420,15 @@ def set_strict_flags() -> None:
fail(f"Package name '{p}' cannot have a slash in it.", stderr, options)
p_targets = cache.find_modules_recursive(p)
if not p_targets:
fail(f"Can't find package '{p}'", stderr, options)
reason = cache.find_module(p)
if reason is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
fail(
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",
stderr,
options,
)
else:
fail(f"Can't find package '{p}'", stderr, options)
targets.extend(p_targets)
for m in special_opts.modules:
targets.append(BuildSource(None, m, None))
Expand Down

0 comments on commit 33717e5

Please sign in to comment.