Repository: python/mypy

Issue:
Error code misc and build errors
It probably shouldn't be possible to "disable" build errors at all, let alone under an overloaded and innocuous looking error code (note the new, clearer summary for blocking errors is unreleased / from https://github.com/python/mypy/pull/9674).

```
λ mkdir -p package/a  
λ mkdir -p package/b
λ echo 'x: int = "asdf"' >> package/b/x.py
λ echo 'y: str = 0' >> package/a/x.py
λ echo 'another_error: int = "adsf"' > package/unrelated.py

λ mypy package --show-error-codes                          
package/b/x.py: error: Duplicate module named 'x' (also at 'package/a/x.py')  [misc]
Found 1 error in 1 file (errors prevented further checking)

λ mypy package --show-error-codes --disable-error-code misc
Success: no issues found in 3 source files
```

Thanks to @ehossack for mentioning that people are doing this.


Discussion:

Resolving patch:
diff --git a/mypy/build.py b/mypy/build.py
--- a/mypy/build.py
+++ b/mypy/build.py
@@ -2748,7 +2748,8 @@ def load_graph(sources: List[BuildSource], manager: BuildManager,
             manager.errors.set_file(st.xpath, st.id)
             manager.errors.report(
                 -1, -1,
-                "Duplicate module named '%s' (also at '%s')" % (st.id, graph[st.id].xpath)
+                "Duplicate module named '%s' (also at '%s')" % (st.id, graph[st.id].xpath),
+                blocker=True,
             )
             p1 = len(pathlib.PurePath(st.xpath).parents)
             p2 = len(pathlib.PurePath(graph[st.id].xpath).parents)
diff --git a/mypy/errors.py b/mypy/errors.py
--- a/mypy/errors.py
+++ b/mypy/errors.py
@@ -316,7 +316,7 @@ def report(self,
         if end_line is None:
             end_line = origin_line
 
-        code = code or codes.MISC
+        code = code or (codes.MISC if not blocker else None)
 
         info = ErrorInfo(self.import_context(), file, self.current_module(), type,
                          function, line, column, severity, message, code,
@@ -357,14 +357,17 @@ def add_error_info(self, info: ErrorInfo) -> None:
         self._add_error_info(file, info)
 
     def is_ignored_error(self, line: int, info: ErrorInfo, ignores: Dict[int, List[str]]) -> bool:
+        if info.blocker:
+            # Blocking errors can never be ignored
+            return False
         if info.code and self.is_error_code_enabled(info.code) is False:
             return True
-        elif line not in ignores:
+        if line not in ignores:
             return False
-        elif not ignores[line]:
+        if not ignores[line]:
             # Empty list means that we ignore all errors
             return True
-        elif info.code and self.is_error_code_enabled(info.code) is True:
+        if info.code and self.is_error_code_enabled(info.code) is True:
             return info.code.code in ignores[line]
         return False
 


Test patch:
diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test
--- a/test-data/unit/cmdline.test
+++ b/test-data/unit/cmdline.test
@@ -1241,3 +1241,14 @@ class Thing: ...
 [out]
 Success: no issues found in 1 source file
 == Return code: 0
+
+[case testBlocker]
+# cmd: mypy pkg --error-summary --disable-error-code syntax
+[file pkg/x.py]
+public static void main(String[] args)
+[file pkg/y.py]
+x: str = 0
+[out]
+pkg/x.py:1: error: invalid syntax
+Found 1 error in 1 file (errors prevented further checking)
+== Return code: 2