Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstring parser to remove duplicate in Gymnasium website #329

Merged
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
17 changes: 17 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@
autoclass_content = "both"
autodoc_preserve_defaults = True


# This function removes the content before the parameters in the __init__ function.
# This content is often not useful for the website documentation as it replicates
# the class docstring.
def remove_lines_before_parameters(app, what, name, obj, options, lines):
if what == "class":
# ":" represents args values such as :param: or :raises:
first_idx_to_keep = next(
(i for i, line in enumerate(lines) if line.startswith(":")), 0
)
lines[:] = lines[first_idx_to_keep:]


def setup(app):
app.connect("autodoc-process-docstring", remove_lines_before_parameters)


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand Down
15 changes: 3 additions & 12 deletions gymnasium/spaces/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class Dict(Space[typing.Dict[str, Any]], typing.Mapping[str, Space[Any]]):
Elements of this space are (ordered) dictionaries of elements from the constituent spaces.

Example:
>>> from gymnasium.spaces import Dict, Discrete
>>> observation_space = Dict({"position": Discrete(2), "velocity": Discrete(3)}, seed=42)
>>> from gymnasium.spaces import Dict, Box, Discrete
>>> observation_space = Dict({"position": Box(-1, 1, shape=(2,)), "color": Discrete(3)}, seed=42)
>>> observation_space.sample()
OrderedDict([('position', 0), ('velocity', 2)])
OrderedDict([('color', 0), ('position', array([-0.3991573 , 0.21649833], dtype=float32))])

With a nested dict:

Expand Down Expand Up @@ -65,15 +65,6 @@ def __init__(
spaces: A dictionary of spaces. This specifies the structure of the :class:`Dict` space
seed: Optionally, you can use this argument to seed the RNGs of the spaces that make up the :class:`Dict` space.
**spaces_kwargs: If ``spaces`` is ``None``, you need to pass the constituent spaces as keyword arguments, as described above.

Example:
>>> from gymnasium.spaces import Dict, Box, Discrete
>>> observation_space = Dict({"position": Box(-1, 1, shape=(2,)), "color": Discrete(3)}, seed=42)
>>> observation_space.sample()
OrderedDict([('color', 0), ('position', array([-0.3991573 , 0.21649833], dtype=float32))])
>>> observation_space = Dict(position=Box(-1, 1, shape=(2,)), color=Discrete(3), seed=42)
>>> observation_space.sample()
OrderedDict([('position', array([0.6273108, 0.240238 ], dtype=float32)), ('color', 2)])
"""
# Convert the spaces into an OrderedDict
if isinstance(spaces, collections.abc.Mapping) and not isinstance(
Expand Down
4 changes: 0 additions & 4 deletions gymnasium/wrappers/step_api_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class StepAPICompatibility(gym.Wrapper):
New step API refers to step() method returning (observation, reward, terminated, truncated, info)
(Refer to docs for details on the API change)

Args:
env (gym.Env): the env to wrap. Can be in old or new API
output_truncation_bool (bool): Apply to convert environment to use new step API that returns two bool. (True by default)

Example:
>>> import gymnasium as gym
>>> from gymnasium.wrappers import StepAPICompatibility
Expand Down