Skip to content

Replace Callable with Protocol + ParamSpec #574

@Rocamonde

Description

@Rocamonde

Type definitions like

PolicyLoaderFn = Callable[..., policies.BasePolicy]

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:
        ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions