Skip to content

Commit

Permalink
Add docstring parser to remove duplicate in Gymnasium website (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcharraut authored Feb 15, 2023
1 parent 54a2858 commit 5bb67ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
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

1 comment on commit 5bb67ee

@vercel
Copy link

@vercel vercel bot commented on 5bb67ee Feb 17, 2023

Choose a reason for hiding this comment

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

Please # to comment.