Skip to content

Commit

Permalink
Mention common resolutions for build errors (#12154)
Browse files Browse the repository at this point in the history
Might help with breaking changes that result from #9636

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja committed Feb 9, 2022
1 parent 37d58c3 commit 234344b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 15 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2830,8 +2830,15 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
)
manager.errors.report(
-1, -1,
"Are you missing an __init__.py? Alternatively, consider using --exclude to "
"avoid checking one of them.",
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules " # noqa: E501
"for more info",
severity='note',
)
manager.errors.report(
-1, -1,
"Common resolutions include: a) using `--exclude` to avoid checking one of them, "
"b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or "
"adjusting MYPYPATH",
severity='note'
)

Expand Down Expand Up @@ -2905,6 +2912,12 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
"for more info",
severity='note',
)
manager.errors.report(
-1, 0,
"Common resolutions include: a) adding `__init__.py` somewhere, "
"b) using `--explicit-package-bases` or adjusting MYPYPATH",
severity='note',
)
manager.errors.raise_error()

seen_files[newst_path] = newst
Expand Down
7 changes: 5 additions & 2 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ undef
undef
[out]
dir/a.py: error: Duplicate module named "a" (also at "dir/subdir/a.py")
dir/a.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
dir/a.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
dir/a.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH
== Return code: 2

[case testCmdlineNonPackageSlash]
Expand Down Expand Up @@ -125,7 +126,8 @@ mypy: can't decode file 'a.py': unknown encoding: uft-8
# type: ignore
[out]
two/mod/__init__.py: error: Duplicate module named "mod" (also at "one/mod/__init__.py")
two/mod/__init__.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
two/mod/__init__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
two/mod/__init__.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH
== Return code: 2

[case testFlagsFile]
Expand Down Expand Up @@ -1144,6 +1146,7 @@ import foo.bar
[out]
src/foo/bar.py: error: Source file found twice under different module names: "src.foo.bar" and "foo.bar"
src/foo/bar.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
src/foo/bar.py: note: Common resolutions include: a) adding `__init__.py` somewhere, b) using `--explicit-package-bases` or adjusting MYPYPATH
== Return code: 2

[case testEnableInvalidErrorCode]
Expand Down

0 comments on commit 234344b

Please sign in to comment.