class_docstr: Superclass that is used to define observation and action spaces.
  
  Spaces are crucially used in Gym to define the format of valid actions and observations.
  They serve various purposes:
  
  * They clearly define how to interact with environments, i.e. they specify what actions need to look like
    and what observations will look like
  * They allow us to work with highly structured data (e.g. in the form of elements of :class:`Dict` spaces)
    and painlessly transform them into flat arrays that can be used in learning code
  * They provide a method to sample random elements. This is especially useful for exploration and debugging.
  
  Different spaces can be combined hierarchically via container spaces (:class:`Tuple` and :class:`Dict`) to build a
  more expressive space
  
  Warning:
      Custom observation & action spaces can inherit from the ``Space``
      class. However, most use-cases should be covered by the existing space
      classes (e.g. :class:`Box`, :class:`Discrete`, etc...), and container classes (:class`Tuple` &
      :class:`Dict`). Note that parametrized probability distributions (through the
      :meth:`Space.sample()` method), and batching functions (in :class:`gym.vector.VectorEnv`), are
      only well-defined for instances of spaces provided in gym by default.
      Moreover, some implementations of Reinforcement Learning algorithms might
      not handle custom spaces properly. Use custom spaces with care.
class_docstr_tok: ["Superclass","that","is","used","to","define","observation","and","action","spaces",".","Spaces","are","crucially","used","in","Gym","to","define","the","format","of","valid","actions","and","observations",".","They","serve","various","purposes",":","*","They","clearly","define","how","to","interact","with","environments",",","i.e",".","they","specify","what","actions","need","to","look","like","and","what","observations","will","look","like","*","They","allow","us","to","work","with","highly","structured","data","(","e.g",".","in","the","form","of","elements","of",":","class",":","`","Dict","`","spaces",")","and","painlessly","transform","them","into","flat","arrays","that","can","be","used","in","learning","code","*","They","provide","a","method","to","sample","random","elements",".","This","is","especially","useful","for","exploration","and","debugging",".","Different","spaces","can","be","combined","hierarchically","via","container","spaces","(",":","class",":","`","Tuple","`","and",":","class",":","`","Dict","`",")","to","build","a","more","expressive","space","Warning",":","Custom","observation","&","action","spaces","can","inherit","from","the","``","Space","``","class",".","However",",","most","use-cases","should","be","covered","by","the","existing","space","classes","(","e.g",".",":","class",":","`","Box","`",",",":","class",":","`","Discrete","`",",","etc","...",")",",","and","container","classes","(",":","class","`","Tuple","`","&",":","class",":","`","Dict","`",")",".","Note","that","parametrized","probability","distributions","(","through","the",":","meth",":","`","Space.sample","(",")","`","method",")",",","and","batching","functions","(","in",":","class",":","`","gym.vector.VectorEnv","`",")",",","are","only","well-defined","for","instances","of","spaces","provided","in","gym","by","default",".","Moreover",",","some","implementations","of","Reinforcement","Learning","algorithms","might","not","handle","custom","spaces","properly",".","Use","custom","spaces","with","care","."]
docstr: Used when loading a pickled space.
  
  This method was implemented explicitly to allow for loading of legacy states.
  
  Args:
      state: The updated state value
docstr_tok: ["Used","when","loading","a","pickled","space",".","This","method","was","implemented","explicitly","to","allow","for","loading","of","legacy","states",".","Args",":","state",":","The","updated","state","value"]
code: def __setstate__(self, state: Union[Iterable, Mapping]):
      """Used when loading a pickled space.
  
      This method was implemented explicitly to allow for loading of legacy states.
  
      Args:
          state: The updated state value
      """
      # Don't mutate the original state
      state = dict(state)
  
      # Allow for loading of legacy states.
      # See:
      #   https://github.com/openai/gym/pull/2397 -- shape
      #   https://github.com/openai/gym/pull/1913 -- np_random
      #
      if "shape" in state:
          state["_shape"] = state["shape"]
          del state["shape"]
      if "np_random" in state:
          state["_np_random"] = state["np_random"]
          del state["np_random"]
  
      # Update our state
      self.__dict__.update(state)
  
file_path: gym/gym/spaces/space.py
imports: from typing import Any, Generic, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union
  import numpy
  from gym.utils import seeding
label_desc: Use image node_id 9 for calling the Space obj's underlying member method code with example usage: obj.__setstate__(state) without return types