@@ -222,12 +222,13 @@ def filtered_errors(self) -> list[ErrorInfo]:
222222
223223class LoopErrorWatcher (ErrorWatcher ):
224224 """Error watcher that filters and separately collects unreachable errors, redundant
225- expression errors, and revealed type notes when analysing loops iteratively to help
226- avoid making too-hasty reports."""
225+ expression errors, and revealed types when analysing loops iteratively to help avoid
226+ making too-hasty reports."""
227227
228- # Meaning of the entries : ErrorCode, message, line, column, end_line, end_column:
228+ # Meaning of the tuple items : ErrorCode, message, line, column, end_line, end_column:
229229 useless_statements : set [tuple [ErrorCode , str , int , int , int , int ]]
230- revealed_types : set [tuple [ErrorCode , str , int , int , int , int ]]
230+ # Meaning of the tuple items: function_or_member, line, column, end_line, end_column:
231+ revealed_types : dict [tuple [str | None , int , int , int , int ], set [str ]]
231232
232233 def __init__ (
233234 self ,
@@ -244,7 +245,7 @@ def __init__(
244245 filter_deprecated = filter_deprecated ,
245246 )
246247 self .useless_statements = set ()
247- self .revealed_types = set ( )
248+ self .revealed_types = defaultdict ( set )
248249
249250 def on_error (self , file : str , info : ErrorInfo ) -> bool :
250251 if info .code in (codes .UNREACHABLE , codes .REDUNDANT_EXPR ):
@@ -253,9 +254,12 @@ def on_error(self, file: str, info: ErrorInfo) -> bool:
253254 )
254255 return True
255256 if info .code == codes .MISC and info .message .startswith ("Revealed type is " ):
256- self .revealed_types .add (
257- (info .code , info .message , info .line , info .column , info .end_line , info .end_column )
258- )
257+ key = info .function_or_member , info .line , info .column , info .end_line , info .end_column
258+ types = info .message .split ('"' )[1 ]
259+ if types .startswith ("Union[" ):
260+ self .revealed_types [key ].update (types [6 :- 1 ].split (", " ))
261+ else :
262+ self .revealed_types [key ].add (types )
259263 return True
260264 return super ().on_error (file , info )
261265
0 commit comments