imitation icon indicating copy to clipboard operation
imitation copied to clipboard

Replace Callable with Protocol + ParamSpec

Open Rocamonde opened this issue 3 years ago • 0 comments

Type definitions like https://github.com/HumanCompatibleAI/imitation/blob/4232b454b61181e322a666b7ef4c684afa587516/src/imitation/policies/serialize.py#L23-L23

can (and should be, for better type safety) replaced with the usage of Protocol + ParamSpec.

Example:

from typing import ParamSpec, Protocol

P = ParamSpec("P")

class PolicyLoaderFn(Protocol[P]):
    def __call__(self, venv: vec_env.VecEnv, *args: P.args, **kwargs: P.kwargs) -> policies.BasePolicy:
        ...

Rocamonde avatar Oct 07 '22 15:10 Rocamonde