another option to write this block:

```
for i, (msg, pkt) in enumerate(self.packets):
    if klass is None or isinstance(msg, klass):
        self.packets.pop(i)
        return (msg, pkt)
```