Skip to content

Commit

Permalink
build: disallow ignoring blocking errors
Browse files Browse the repository at this point in the history
Fixes python#9727 (and effectively also adds a test for python#9674)
  • Loading branch information
hauntsaninja committed Nov 17, 2020
1 parent 260ac5f commit bf5a2aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bf5a2aa

Please sign in to comment.