class_docstr: A dictionary of :class:`Space` instances.
  
  Elements of this space are (ordered) dictionaries of elements from the constituent spaces.
  
  Example usage:
  
      >>> from gym.spaces import Dict, Discrete
      >>> observation_space = Dict({"position": Discrete(2), "velocity": Discrete(3)})
      >>> observation_space.sample()
      OrderedDict([('position', 1), ('velocity', 2)])
  
  Example usage [nested]::
  
      >>> from gym.spaces import Box, Dict, Discrete, MultiBinary, MultiDiscrete
      >>> Dict(
      ...     {
      ...         "ext_controller": MultiDiscrete([5, 2, 2]),
      ...         "inner_state": Dict(
      ...             {
      ...                 "charge": Discrete(100),
      ...                 "system_checks": MultiBinary(10),
      ...                 "job_status": Dict(
      ...                     {
      ...                         "task": Discrete(5),
      ...                         "progress": Box(low=0, high=100, shape=()),
      ...                     }
      ...                 ),
      ...             }
      ...         ),
      ...     }
      ... )
  
  It can be convenient to use :class:`Dict` spaces if you want to make complex observations or actions more human-readable.
  Usually, it will not be possible to use elements of this space directly in learning code. However, you can easily
  convert `Dict` observations to flat arrays by using a :class:`gym.wrappers.FlattenObservation` wrapper. Similar wrappers can be
  implemented to deal with :class:`Dict` actions.
docstr: Constructor of :class:`Dict` space.
  
  This space can be instantiated in one of two ways: Either you pass a dictionary
  of spaces to :meth:`__init__` via the ``spaces`` argument, or you pass the spaces as separate
  keyword arguments (where you will need to avoid the keys ``spaces`` and ``seed``)
  
  Example::
  
      >>> from gym.spaces import Box, Discrete
      >>> Dict({"position": Box(-1, 1, shape=(2,)), "color": Discrete(3)})
      Dict(color:Discrete(3), position:Box(-1.0, 1.0, (2,), float32))
      >>> Dict(position=Box(-1, 1, shape=(2,)), color=Discrete(3))
      Dict(color:Discrete(3), position:Box(-1.0, 1.0, (2,), float32))
  
  Args:
      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.
docstr_tok: ["Constructor","of",":","class",":","`","Dict","`","space",".","This","space","can","be","instantiated","in","one","of","two","ways",":","Either","you","pass","a","dictionary","of","spaces","to",":","meth",":","`","__init__","`","via","the","``","spaces","``","argument",",","or","you","pass","the","spaces","as","separate","keyword","arguments","(","where","you","will","need","to","avoid","the","keys","``","spaces","``","and","``","seed","``",")","Example",":",":",">",">",">","from","gym.spaces","import","Box",",","Discrete",">",">",">","Dict","(","{","``","position","''",":","Box","(","-1",",","1",",","shape=","(","2",",",")",")",",","``","color","''",":","Discrete","(","3",")","}",")","Dict","(","color",":","Discrete","(","3",")",",","position",":","Box","(","-1.0",",","1.0",",","(","2",",",")",",","float32",")",")",">",">",">","Dict","(","position=Box","(","-1",",","1",",","shape=","(","2",",",")",")",",","color=Discrete","(","3",")",")","Dict","(","color",":","Discrete","(","3",")",",","position",":","Box","(","-1.0",",","1.0",",","(","2",",",")",",","float32",")",")","Args",":","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","."]
code: def __init__(
      self,
      spaces: Optional[
          Union[
              TypingDict[str, Space],
              TypingSequence[Tuple[str, Space]],
          ]
      ] = None,
      seed: Optional[Union[dict, int, np.random.Generator]] = None,
      **spaces_kwargs: Space,
  ):
      """Constructor of :class:`Dict` space.
  
      This space can be instantiated in one of two ways: Either you pass a dictionary
      of spaces to :meth:`__init__` via the ``spaces`` argument, or you pass the spaces as separate
      keyword arguments (where you will need to avoid the keys ``spaces`` and ``seed``)
  
      Example::
  
          >>> from gym.spaces import Box, Discrete
          >>> Dict({"position": Box(-1, 1, shape=(2,)), "color": Discrete(3)})
          Dict(color:Discrete(3), position:Box(-1.0, 1.0, (2,), float32))
          >>> Dict(position=Box(-1, 1, shape=(2,)), color=Discrete(3))
          Dict(color:Discrete(3), position:Box(-1.0, 1.0, (2,), float32))
  
      Args:
          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.
      """
      # Convert the spaces into an OrderedDict
      if isinstance(spaces, Mapping) and not isinstance(
          spaces, OrderedDict
      ):
          try:
              spaces = OrderedDict(sorted(spaces.items()))
          except TypeError:
              # Incomparable types (e.g. `int` vs. `str`, or user-defined types) found.
              # The keys remain in the insertion order.
              spaces = OrderedDict(spaces.items())
      elif isinstance(spaces, Sequence):
          spaces = OrderedDict(spaces)
      elif spaces is None:
          spaces = OrderedDict()
      else:
          assert isinstance(
              spaces, OrderedDict
          ), f"Unexpected Dict space input, expecting dict, OrderedDict or Sequence, actual type: {type(spaces)}"
  
      # Add kwargs to spaces to allow both dictionary and keywords to be used
      for key, space in spaces_kwargs.items():
          if key not in spaces:
              spaces[key] = space
          else:
              raise ValueError(
                  f"Dict space keyword '{key}' already exists in the spaces dictionary."
              )
  
      self.spaces = spaces
      for key, space in self.spaces.items():
          assert isinstance(
              space, Space
          ), f"Dict space element is not an instance of Space: key='{key}', space={space}"
  
      super().__init__(None, None, seed)  # type: ignore
  
imports: from collections import OrderedDict
  from collections.abc import Mapping, Sequence
  from typing import Any
  from typing import Dict
  from typing import List, Optional
  from typing import Sequence
  from typing import Tuple, Union
  import numpy
  from gym.spaces.space import Space
label_desc: Use image node_id 1 to create a new Dict object from inherited base classes: Space, Mapping with example: obj = Dict(spaces, seed)