Skip to content
This repository was archived by the owner on Sep 10, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions mixtape/core/analysis/ray_utils/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from ray.rllib.env import PettingZooEnv
from ray.rllib.env.wrappers.pettingzoo_env import ParallelPettingZooEnv

if TYPE_CHECKING:
import numpy.typing as npt
Comment on lines +9 to +10

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://numpy.org/doc/stable/reference/typing.html#api and other usage in the code.

For a rigorous library like numpy, there ought to be no need to import private symbols (it's a red flag that "there ought to be a better way"). I appreciate this doesn't hold for other lower-software-quality libraries.



class PZWrapper(PettingZooEnv):
"""Temporary wrapper for PettingZooEnv.
Expand All @@ -11,12 +18,13 @@ class PZWrapper(PettingZooEnv):
render function, but PettingZoo environments no longer accept an argument.
"""

def render(self) -> np._typing.NDArray[np.uint8]:
# Superclass return type is incorrect:
# https://github.com/Farama-Foundation/Gymnasium/issues/845#issuecomment-2535827312
def render(self) -> npt.NDArray[np.uint8]: # type: ignore[override]
"""RGB image given the current observation.

Returns:
np._typing.NDArray[np.uint8]: A numpy uint8 3D array (image) to
render.
Comment on lines -18 to -19

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings are nice for explaining the semantics of parameters and return values, but I think we should avoid duplicating type information in them.

Of course, before formal Python typing via language syntax, it was more common to put type information in docstrings.

A numpy uint8 3D array (image) to render.
"""
return self.env.render()

Expand All @@ -29,11 +37,12 @@ class ParallelPZWrapper(ParallelPettingZooEnv):
render function, but PettingZoo environments no longer accept an argument.
"""

def render(self) -> np._typing.NDArray[np.uint8]:
# Superclass return type is incorrect:
# https://github.com/Farama-Foundation/Gymnasium/issues/845#issuecomment-2535827312
def render(self) -> npt.NDArray[np.uint8]: # type: ignore[override]
"""RGB image given the current observation.

Returns:
np._typing.NDArray[np.uint8]: A numpy uint8 3D array (image) to
render.
A numpy uint8 3D array (image) to render.
"""
return self.par_env.render()
2 changes: 2 additions & 0 deletions mixtape/core/ray_utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

from django.db import models


Expand Down