File size: 986 Bytes
079c32c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from abc import abstractmethod
from typing import Any

from .env_element import EnvElement, IEnvElement, EnvElementInfo
from ..env.base_env import BaseEnv


class IEnvElementRunner(IEnvElement):

    @abstractmethod
    def get(self, engine: BaseEnv) -> Any:
        raise NotImplementedError

    @abstractmethod
    def reset(self, *args, **kwargs) -> None:
        raise NotImplementedError


class EnvElementRunner(IEnvElementRunner):

    def __init__(self, *args, **kwargs) -> None:
        self._init(*args, **kwargs)
        self._check()

    @abstractmethod
    def _init(self, *args, **kwargs) -> None:
        # set self._core and other state variable
        raise NotImplementedError

    def _check(self) -> None:
        flag = [hasattr(self, '_core'), isinstance(self._core, EnvElement)]
        assert all(flag), flag

    def __repr__(self) -> str:
        return repr(self._core)

    @property
    def info(self) -> 'EnvElementInfo':
        return self._core.info