mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-07-31 05:44:31 +00:00
Add docstring parser to remove duplicate in Gymnasium website (#329)
This commit is contained in:
17
docs/conf.py
17
docs/conf.py
@@ -66,6 +66,23 @@ napoleon_custom_sections = [("Returns", "params_style")]
|
||||
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
|
||||
|
@@ -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 @@ class Dict(Space[typing.Dict[str, Any]], typing.Mapping[str, Space[Any]]):
|
||||
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(
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user