Skip to content

Commit 1bf48b1

Browse files
committed
minify baseline and format it
1 parent 5d5f34c commit 1bf48b1

File tree

2 files changed

+22320
-24
lines changed

2 files changed

+22320
-24
lines changed

.mypy/baseline.json

+22,292-1
Large diffs are not rendered by default.

mypy/errors.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os.path
3+
import re
34
import sys
45
import traceback
56
from pathlib import Path
@@ -8,7 +9,7 @@
89
from collections import defaultdict
910

1011
from typing import Tuple, List, TypeVar, Set, Dict, Optional, TextIO, Callable
11-
from typing_extensions import Final
12+
from typing_extensions import Final, TypedDict
1213

1314
from mypy.scope import Scope
1415
from mypy.options import Options
@@ -140,18 +141,10 @@ def filter_prefix(error_map: Dict[str, List[ErrorInfo]]) -> Dict[str, List[Error
140141
return result
141142

142143

143-
def baseline_json_hook(d: Dict[str, object]) -> object:
144-
class_ = d.pop(".class", None)
145-
if class_ is None:
146-
return d
147-
if class_ == "mypy.errors.ErrorInfo":
148-
result = object.__new__(ErrorInfo)
149-
elif class_ == "mypy.errorcodes.ErrorCode":
150-
result = object.__new__(ErrorCode)
151-
else:
152-
raise Exception(f"unknown class {class_!r}")
153-
result.__dict__ = d
154-
return result
144+
class BaselineError(TypedDict):
145+
line: int
146+
code: str
147+
message: str
155148

156149

157150
class Errors:
@@ -211,7 +204,7 @@ class Errors:
211204
seen_import_error = False
212205

213206
# Error baseline
214-
baseline: Dict[str, List[ErrorInfo]] = {}
207+
baseline: Dict[str, List[BaselineError]] = {}
215208
# All detected errors before baseline filter
216209
all_errors: Dict[str, List[ErrorInfo]] = {}
217210

@@ -808,20 +801,26 @@ def save_baseline(self, file: Path) -> None:
808801
if not file.parent.exists():
809802
file.parent.mkdir()
810803
json.dump(
811-
filter_prefix(self.error_info_map),
804+
{
805+
file: [
806+
{
807+
"line": error.line,
808+
"code": error.code.code,
809+
"message": error.message
810+
} for error in errors
811+
]
812+
for file, errors in filter_prefix(self.error_info_map).items()
813+
},
812814
file.open("w"),
813-
default=lambda o: {
814-
**{".class": type(o).__module__ + "." + type(o).__qualname__},
815-
**o.__dict__,
816-
}
815+
indent=2,
817816
)
818817

819818
def load_baseline(self, file: Path) -> bool:
820819
"""Load baseline errors from baseline file"""
821820

822821
if not file.exists():
823822
return False
824-
self.baseline = json.load(file.open("r"), object_hook=baseline_json_hook)
823+
self.baseline = json.load(file.open("r"))
825824
return True
826825

827826
def filter_baseline(self) -> None:
@@ -837,16 +836,22 @@ def filter_baseline(self) -> None:
837836
for error in errors:
838837
for baseline_error in baseline_errors:
839838
if (
840-
error.line == baseline_error.line and error.code == baseline_error.code
841-
or error.message == baseline_error.message and
842-
abs(error.line - baseline_error.line) < 50
839+
error.line == baseline_error["line"] and
840+
error.code.code == baseline_error["code"]
841+
or clean_baseline_message(error.message) ==
842+
clean_baseline_message(baseline_error["message"]) and
843+
abs(error.line - baseline_error["line"]) < 50
843844
):
844845
break
845846
else:
846847
new_errors.append(error)
847848
self.error_info_map[file] = new_errors
848849

849850

851+
def clean_baseline_message(message: str) -> str:
852+
return re.sub(r"line \r.", message, "")
853+
854+
850855
class CompileError(Exception):
851856
"""Exception raised when there is a compile error.
852857

0 commit comments

Comments
 (0)