@@ -120,18 +120,30 @@ def __init__(self,
120
120
Optional [ErrorCode ]]
121
121
122
122
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
+ }
125
129
for errors in result .values ():
126
130
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
+ ]
129
140
return result
130
141
131
142
132
- def baseline_json_hook (d : Dict [str , object ]):
143
+ def baseline_json_hook (d : Dict [str , object ]) -> object :
133
144
class_ = d .pop (".class" , None )
134
- if class_ is None : return d
145
+ if class_ is None :
146
+ return d
135
147
if class_ == "mypy.errors.ErrorInfo" :
136
148
result = object .__new__ (ErrorInfo )
137
149
elif class_ == "mypy.errorcodes.ErrorCode" :
@@ -199,9 +211,9 @@ class Errors:
199
211
seen_import_error = False
200
212
201
213
# Error baseline
202
- baseline : dict [str , list [ErrorInfo ]] = {}
214
+ baseline : Dict [str , List [ErrorInfo ]] = {}
203
215
# All detected errors before baseline filter
204
- all_errors : dict [str , list [ErrorInfo ]] = {}
216
+ all_errors : Dict [str , List [ErrorInfo ]] = {}
205
217
206
218
def __init__ (self ,
207
219
show_error_context : bool = False ,
@@ -804,21 +816,23 @@ def save_baseline(self, file: Path) -> None:
804
816
}
805
817
)
806
818
807
- def load_baseline (self , file : Path ) -> None :
819
+ def load_baseline (self , file : Path ) -> bool :
808
820
"""Load baseline errors from baseline file"""
809
821
810
822
if not file .exists ():
811
- return
823
+ return False
812
824
self .baseline = json .load (file .open ("r" ), object_hook = baseline_json_hook )
825
+ return True
813
826
814
827
def filter_baseline (self ) -> None :
815
828
"""Remove baseline errors from the error_info_map"""
816
829
817
830
self .all_errors = self .error_info_map .copy ()
818
831
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 , "/" ))
820
834
if not baseline_errors :
821
- return
835
+ continue
822
836
new_errors = []
823
837
for error in errors :
824
838
for baseline_error in baseline_errors :
0 commit comments