File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -206,12 +206,18 @@ def __len__(self) -> int:
206
206
return len (self ._list )
207
207
208
208
def pop (self , cls : Type [Warning ] = Warning ) -> "warnings.WarningMessage" :
209
- """Pop the first recorded warning, raise exception if not exists."""
209
+ """Pop the first recorded warning (or subclass of warning), raise exception if not exists."""
210
+ matches = []
210
211
for i , w in enumerate (self ._list ):
211
- if issubclass ( w .category , cls ) :
212
+ if w .category == cls :
212
213
return self ._list .pop (i )
213
- __tracebackhide__ = True
214
- raise AssertionError (f"{ cls !r} not found in warning list" )
214
+ if issubclass (w .category , cls ):
215
+ matches .append ((i , w ))
216
+ if not matches :
217
+ __tracebackhide__ = True
218
+ raise AssertionError (f"{ cls !r} not found in warning list" )
219
+ (idx , best ), * rest = matches
220
+ return self ._list .pop (idx )
215
221
216
222
def clear (self ) -> None :
217
223
"""Clear the list of recorded warnings."""
You can’t perform that action at this time.
0 commit comments