Skip to content

Commit

Permalink
baseline: show baselined errors as notes (baseline-as-notes)
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Jul 20, 2022
1 parent 4d989ce commit 2b519d1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@ def process_stale_scc(graph: Graph, scc: List[str], manager: BuildManager) -> No
for id in stale:
graph[id].transitive_error = True
for id in stale:
manager.errors.filter_baseline(graph[id].xpath)
manager.errors.filter_baseline(graph[id].xpath, manager.options.baseline_as_notes)
# show new errors only
manager.flush_errors(
manager.errors.file_messages(graph[id].xpath),
Expand Down
14 changes: 11 additions & 3 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ def prepare_baseline_errors(self, baseline_format: str) -> Dict[
del error["line"]
return result

def filter_baseline(self, path: str) -> None:
def filter_baseline(self, path: str, as_notes: bool) -> None:
"""Remove baseline errors from the error_info_map"""
if path not in self.error_info_map:
return
Expand All @@ -1001,8 +1001,12 @@ def filter_baseline(self, path: str) -> None:
clean_baseline_message(error.message) ==
clean_baseline_message(baseline_error["message"])
):
ignored_notes.extend([id(note) for note in error.notes])
del baseline_errors[i]
if as_notes:
new_errors.append(error)
error.severity = "note"
else:
ignored_notes.extend([id(note) for note in error.notes])
break
else:
new_errors.append(error)
Expand All @@ -1023,8 +1027,12 @@ def filter_baseline(self, path: str) -> None:
clean_baseline_message(baseline_error["message"]) and
abs(error.line - baseline_error["line"]) < 100
):
ignored_notes.extend([id(note) for note in error.notes])
del baseline_errors[i]
if as_notes:
error.severity = "note"
new_errors.append(error)
else:
ignored_notes.extend([id(note) for note in error.notes])
break
else:
new_errors.append(error)
Expand Down
3 changes: 3 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ def add_invertible_flag(flag: str,
add_invertible_flag(
'--no-auto-baseline', default=True, group=based_group,
dest="auto_baseline", help="Don't update the baseline automatically.")
add_invertible_flag(
'--baseline-as-notes', group=based_group, default=False,
help="Output the baselined errors as notes (useful for IDEs).")
based_group.add_argument(
'--legacy', action='store_true',
help="Disable all based functionality")
Expand Down
1 change: 1 addition & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def __init__(self) -> None:
self.targets: List[str] = []
self.ignore_any_from_error = True
self.incomplete_is_typed = flip_if_not_based(False)
self.baseline_as_notes = False

# disallow_any options
self.disallow_any_generics = flip_if_not_based(True)
Expand Down

0 comments on commit 2b519d1

Please sign in to comment.