Pop the first recorded warning which is an instance of ``cls``, but not an instance of a child class of any other match. Raises ``AssertionError`` if there is no match.
(self, cls: type[Warning] = Warning)
| 209 | return len(self._list) |
| 210 | |
| 211 | def pop(self, cls: type[Warning] = Warning) -> warnings.WarningMessage: |
| 212 | class="st">"""Pop the first recorded warning which is an instance of ``cls``, |
| 213 | but not an instance of a child class of any other match. |
| 214 | Raises ``AssertionError`` if there is no match. |
| 215 | class="st">""" |
| 216 | best_idx: int | None = None |
| 217 | for i, w in enumerate(self._list): |
| 218 | if w.category == cls: |
| 219 | return self._list.pop(i) class="cm"># exact match, stop looking |
| 220 | if issubclass(w.category, cls) and ( |
| 221 | best_idx is None |
| 222 | or not issubclass(w.category, self._list[best_idx].category) |
| 223 | ): |
| 224 | best_idx = i |
| 225 | if best_idx is not None: |
| 226 | return self._list.pop(best_idx) |
| 227 | __tracebackhide__ = True |
| 228 | raise AssertionError(fclass="st">"{cls!r} not found in warning list") |
| 229 | |
| 230 | def clear(self) -> None: |
| 231 | class="st">""class="st">"Clear the list of recorded warnings."class="st">"" |
no outgoing calls