The only thing I would change is put this into one `if`

```python
if handler and callable(handler) and not handler(data.get(message_type)):
    break
```