Skip to content

lit_sb3.callbacks.convert

[docs] module lit_sb3.callbacks.convert

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from collections.abc import Callable
from typing import Any

from .base import BaseCallback


class ConvertCallback(BaseCallback):
    """Convert functional callback (old-style) to object.

    Args:
        callback:
        verbose: Verbosity level: 0 for no output, 1 for info messages, 2 for debug messages
    """

    def __init__(self, callback: Callable[[dict[str, Any], dict[str, Any]], bool] | None, verbose: int = 0) -> None:
        super().__init__(verbose)
        self.callback = callback

    def _on_step(self) -> bool:
        if self.callback is not None:
            return self.callback(self.locals, self.globals)
        return True