Skip to content

Commit 84cde47

Browse files
committed
add baseline file
1 parent 6d5bf84 commit 84cde47

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

.mypy/baseline.json

+1
Large diffs are not rendered by default.

.mypy/proper_plugin.json

+1
Large diffs are not rendered by default.

mypy/build.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
from mypy.config_parser import parse_mypy_comments
6262
from mypy.freetree import free_tree
6363
from mypy.stubinfo import legacy_bundled_packages, is_legacy_bundled_package
64-
from mypy import errorcodes as codes
65-
64+
from mypy import errorcodes as codes, defaults
6665

6766
# Switch to True to produce debug output related to fine-grained incremental
6867
# mode only that is useful during development. This produces only a subset of
@@ -3176,7 +3175,10 @@ def process_stale_scc(graph: Graph, scc: List[str], manager: BuildManager) -> No
31763175
graph[id].transitive_error = True
31773176
for id in stale:
31783177
if not manager.options.write_baseline:
3179-
manager.errors.load_baseline(Path(manager.options.baseline_file))
3178+
res = manager.errors.load_baseline(Path(manager.options.baseline_file))
3179+
if not res and manager.options.baseline_file != defaults.BASELINE_FILE:
3180+
print("Baseline file not found")
3181+
raise Exception("Baseline file not found")
31803182
if manager.errors.baseline:
31813183
manager.errors.filter_baseline()
31823184
manager.flush_errors(manager.errors.file_messages(graph[id].xpath), False)

mypy/errors.py

+26-12
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,30 @@ def __init__(self,
120120
Optional[ErrorCode]]
121121

122122

123-
def filter_prefix(map: Dict[str, List[ErrorInfo]]) -> Dict[str, List[ErrorInfo]]:
124-
result = {file.removeprefix(os.getcwd()): errors for file, errors in map.items()}
123+
def filter_prefix(error_map: Dict[str, List[ErrorInfo]]) -> Dict[str, List[ErrorInfo]]:
124+
"""Convert absolute paths to relative paths in an error_map"""
125+
result = {
126+
remove_path_prefix(file, os.getcwd()).replace(os.sep, "/"): errors
127+
for file, errors in error_map.items()
128+
}
125129
for errors in result.values():
126130
for error in errors:
127-
error.origin = error.origin[0].removeprefix(os.getcwd()), *error.origin[1:]
128-
error.file = error.file.removeprefix(os.getcwd())
131+
error.origin = remove_path_prefix(
132+
error.origin[0], os.getcwd()).replace(os.sep, "/"), *error.origin[1:]
133+
error.file = remove_path_prefix(error.file, os.getcwd()).replace(os.sep, "/")
134+
error.import_ctx = [
135+
(
136+
remove_path_prefix(import_ctx[0], os.getcwd()).replace(os.sep, "/"),
137+
import_ctx[1],
138+
) for import_ctx in error.import_ctx
139+
]
129140
return result
130141

131142

132-
def baseline_json_hook(d: Dict[str, object]):
143+
def baseline_json_hook(d: Dict[str, object]) -> object:
133144
class_ = d.pop(".class", None)
134-
if class_ is None: return d
145+
if class_ is None:
146+
return d
135147
if class_ == "mypy.errors.ErrorInfo":
136148
result = object.__new__(ErrorInfo)
137149
elif class_ == "mypy.errorcodes.ErrorCode":
@@ -199,9 +211,9 @@ class Errors:
199211
seen_import_error = False
200212

201213
# Error baseline
202-
baseline: dict[str, list[ErrorInfo]] = {}
214+
baseline: Dict[str, List[ErrorInfo]] = {}
203215
# All detected errors before baseline filter
204-
all_errors: dict[str, list[ErrorInfo]] = {}
216+
all_errors: Dict[str, List[ErrorInfo]] = {}
205217

206218
def __init__(self,
207219
show_error_context: bool = False,
@@ -804,21 +816,23 @@ def save_baseline(self, file: Path) -> None:
804816
}
805817
)
806818

807-
def load_baseline(self, file: Path) -> None:
819+
def load_baseline(self, file: Path) -> bool:
808820
"""Load baseline errors from baseline file"""
809821

810822
if not file.exists():
811-
return
823+
return False
812824
self.baseline = json.load(file.open("r"), object_hook=baseline_json_hook)
825+
return True
813826

814827
def filter_baseline(self) -> None:
815828
"""Remove baseline errors from the error_info_map"""
816829

817830
self.all_errors = self.error_info_map.copy()
818831
for file, errors in self.error_info_map.items():
819-
baseline_errors = self.baseline.get(file.removeprefix(os.getcwd()))
832+
baseline_errors = self.baseline.get(
833+
remove_path_prefix(file, os.getcwd()).replace(os.sep, "/"))
820834
if not baseline_errors:
821-
return
835+
continue
822836
new_errors = []
823837
for error in errors:
824838
for baseline_error in baseline_errors:

mypy/ipc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,4 @@ def connection_name(self) -> str:
268268
if sys.platform == 'win32':
269269
return self.name
270270
else:
271-
return self.sock.getsockname()
271+
return self.sock.getsockname() # type: ignore[no-any-return, unused-ignore]

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ description = type check ourselves
5151
basepython = python3.7
5252
commands =
5353
python -m mypy --config-file mypy_self_check.ini -p mypy -p mypyc
54-
python -m mypy --config-file mypy_self_check.ini misc/proper_plugin.py
54+
python -m mypy --config-file mypy_self_check.ini --baseline-file .mypy/proper_plugin.json misc/proper_plugin.py
5555

5656
[testenv:docs]
5757
description = invoke sphinx-build to build the HTML docs

0 commit comments

Comments
 (0)