Skip to content

Commit 234344b

Browse files
authored
Mention common resolutions for build errors (#12154)
Might help with breaking changes that result from #9636 Co-authored-by: hauntsaninja <>
1 parent 37d58c3 commit 234344b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

mypy/build.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -2830,8 +2830,15 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
28302830
)
28312831
manager.errors.report(
28322832
-1, -1,
2833-
"Are you missing an __init__.py? Alternatively, consider using --exclude to "
2834-
"avoid checking one of them.",
2833+
"See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules " # noqa: E501
2834+
"for more info",
2835+
severity='note',
2836+
)
2837+
manager.errors.report(
2838+
-1, -1,
2839+
"Common resolutions include: a) using `--exclude` to avoid checking one of them, "
2840+
"b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or "
2841+
"adjusting MYPYPATH",
28352842
severity='note'
28362843
)
28372844

@@ -2905,6 +2912,12 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
29052912
"for more info",
29062913
severity='note',
29072914
)
2915+
manager.errors.report(
2916+
-1, 0,
2917+
"Common resolutions include: a) adding `__init__.py` somewhere, "
2918+
"b) using `--explicit-package-bases` or adjusting MYPYPATH",
2919+
severity='note',
2920+
)
29082921
manager.errors.raise_error()
29092922

29102923
seen_files[newst_path] = newst

test-data/unit/cmdline.test

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ undef
5959
undef
6060
[out]
6161
dir/a.py: error: Duplicate module named "a" (also at "dir/subdir/a.py")
62-
dir/a.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
62+
dir/a.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
63+
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
6364
== Return code: 2
6465

6566
[case testCmdlineNonPackageSlash]
@@ -125,7 +126,8 @@ mypy: can't decode file 'a.py': unknown encoding: uft-8
125126
# type: ignore
126127
[out]
127128
two/mod/__init__.py: error: Duplicate module named "mod" (also at "one/mod/__init__.py")
128-
two/mod/__init__.py: note: Are you missing an __init__.py? Alternatively, consider using --exclude to avoid checking one of them.
129+
two/mod/__init__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
130+
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
129131
== Return code: 2
130132

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

11491152
[case testEnableInvalidErrorCode]

0 commit comments

Comments
 (0)