code: def legacy_patch_shapes(space):
      
  
      if not hasattr(space, "shape"):
          if isinstance(space, gym.spaces.Discrete):
              space.shape = ()
          elif isinstance(space, gym.spaces.Tuple):
              shapes = []
              for s in space.spaces:
                  shape = legacy_patch_shapes(s)
                  shapes.append(shape)
              space.shape = tuple(shapes)
  
      return space.shape
docs: Assigns shapes to spaces that don't have shapes.
  
      This is only needed for older gym versions that don't set shapes properly
      for Tuple and Discrete spaces.