Farama-Foundation / Gymnasium

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)

Home Page:https://gymnasium.farama.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Proposal] Type Hint Error in `async_vector_env`'s `_raise_if_errors` Method Argument

helpingstar opened this issue · comments

Proposal

In the AsyncVectorEnv(VectorEnv) class, the def _raise_if_errors(self, successes: list[bool]): method specifies the type hint for successes as list[bool].

This method is called by the *_wait, _check_spaces, set_attr methods.

However, except for step_wait, all of these use the result of zip() as the argument for success.

results, successes = zip(*[pipe.recv() for pipe in self.parent_pipes])
self._raise_if_errors(successes)

results, successes = zip(*[pipe.recv() for pipe in self.parent_pipes])
self._raise_if_errors(successes)

_, successes = zip(*[pipe.recv() for pipe in self.parent_pipes])
self._raise_if_errors(successes)

results, successes = zip(*[pipe.recv() for pipe in self.parent_pipes])
self._raise_if_errors(successes)

According to the documentation, the zip() function returns an iterator of tuples

Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.

Motivation

No response

Pitch

def _raise_if_errors(self, successes: list[bool]):

I recommend updating the type hint to def _raise_if_errors(self, successes: list[bool] | tuple[bool]): to accurately reflect the data types that may be passed to this method.

Alternatives

No response

Additional context

I categorized the issue as a "Proposal" because it doesn't cause a bug.

If my suggestion is right, I'll PR it.

Checklist

  • I have checked that there is no similar issue in the repo

Sure, I would be happy to update the type hints for it. Could you make a PR for it?