Skip to content

Commit 2b519d1

Browse files
committed
baseline: show baselined errors as notes (baseline-as-notes)
1 parent 4d989ce commit 2b519d1

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

mypy/build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ def process_stale_scc(graph: Graph, scc: List[str], manager: BuildManager) -> No
33863386
for id in stale:
33873387
graph[id].transitive_error = True
33883388
for id in stale:
3389-
manager.errors.filter_baseline(graph[id].xpath)
3389+
manager.errors.filter_baseline(graph[id].xpath, manager.options.baseline_as_notes)
33903390
# show new errors only
33913391
manager.flush_errors(
33923392
manager.errors.file_messages(graph[id].xpath),

mypy/errors.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ def prepare_baseline_errors(self, baseline_format: str) -> Dict[
977977
del error["line"]
978978
return result
979979

980-
def filter_baseline(self, path: str) -> None:
980+
def filter_baseline(self, path: str, as_notes: bool) -> None:
981981
"""Remove baseline errors from the error_info_map"""
982982
if path not in self.error_info_map:
983983
return
@@ -1001,8 +1001,12 @@ def filter_baseline(self, path: str) -> None:
10011001
clean_baseline_message(error.message) ==
10021002
clean_baseline_message(baseline_error["message"])
10031003
):
1004-
ignored_notes.extend([id(note) for note in error.notes])
10051004
del baseline_errors[i]
1005+
if as_notes:
1006+
new_errors.append(error)
1007+
error.severity = "note"
1008+
else:
1009+
ignored_notes.extend([id(note) for note in error.notes])
10061010
break
10071011
else:
10081012
new_errors.append(error)
@@ -1023,8 +1027,12 @@ def filter_baseline(self, path: str) -> None:
10231027
clean_baseline_message(baseline_error["message"]) and
10241028
abs(error.line - baseline_error["line"]) < 100
10251029
):
1026-
ignored_notes.extend([id(note) for note in error.notes])
10271030
del baseline_errors[i]
1031+
if as_notes:
1032+
error.severity = "note"
1033+
new_errors.append(error)
1034+
else:
1035+
ignored_notes.extend([id(note) for note in error.notes])
10281036
break
10291037
else:
10301038
new_errors.append(error)

mypy/main.py

+3
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ def add_invertible_flag(flag: str,
538538
add_invertible_flag(
539539
'--no-auto-baseline', default=True, group=based_group,
540540
dest="auto_baseline", help="Don't update the baseline automatically.")
541+
add_invertible_flag(
542+
'--baseline-as-notes', group=based_group, default=False,
543+
help="Output the baselined errors as notes (useful for IDEs).")
541544
based_group.add_argument(
542545
'--legacy', action='store_true',
543546
help="Disable all based functionality")

mypy/options.py

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def __init__(self) -> None:
130130
self.targets: List[str] = []
131131
self.ignore_any_from_error = True
132132
self.incomplete_is_typed = flip_if_not_based(False)
133+
self.baseline_as_notes = False
133134

134135
# disallow_any options
135136
self.disallow_any_generics = flip_if_not_based(True)

0 commit comments

Comments
 (0)