code: def flatdim(space: Space) -> int:
      """Return the number of dimensions a flattened equivalent of this space would have.
  
      Example usage::
  
          >>> from gym.spaces import Discrete
          >>> space = Dict({"position": Discrete(2), "velocity": Discrete(3)})
          >>> flatdim(space)
          5
  
      Args:
          space: The space to return the number of dimensions of the flattened spaces
  
      Returns:
          The number of dimensions for the flattened spaces
  
      Raises:
           NotImplementedError: if the space is not defined in ``gym.spaces``.
           ValueError: if the space cannot be flattened into a :class:`Box`
      """
      if not space.is_np_flattenable:
          raise ValueError(
              f"{space} cannot be flattened to a numpy array, probably because it contains a `Graph` or `Sequence` subspace"
          )
  
      raise NotImplementedError(f"Unknown space: `{space}`")
  
imports: import operator
  from collections import OrderedDict
  from functools import reduce, singledispatch
  from typing import Dict
  from typing import TypeVar, Union, cast
  import numpy
  from gym.spaces import Box, Dict, Discrete, Graph, GraphInstance, MultiBinary, MultiDiscrete, Sequence, Space, Text, Tuple
label_desc: Use image node_id 1 for calling a global function with example usage: flatdim(space) without return types