diff --git a/docs/conf.py b/docs/conf.py index dbbb9f8db..cfbe50bc6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/gymnasium/spaces/dict.py b/gymnasium/spaces/dict.py index 48433f293..a9314ed6b 100644 --- a/gymnasium/spaces/dict.py +++ b/gymnasium/spaces/dict.py @@ -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: @@ -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( diff --git a/gymnasium/wrappers/step_api_compatibility.py b/gymnasium/wrappers/step_api_compatibility.py index fed78c344..14fab3f3c 100644 --- a/gymnasium/wrappers/step_api_compatibility.py +++ b/gymnasium/wrappers/step_api_compatibility.py @@ -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