code: def deserialize_type(type_str: str) -> Any:
      """
      Deserializes a type given its full import path as a string, including nested generic types.
  
      This function will dynamically import the module if it's not already imported
      and then retrieve the type object from it. It also handles nested generic types like 'typing.List[typing.Dict[int, str]]'.
  
      :param type_str: The string representation of the type's full import path.
      :return: The deserialized type object.
      :raises DeserializationError: If the type cannot be deserialized due to missing module or type.
      """
  
      def parse_generic_args(args_str):
          args = []
          bracket_count = 0
          current_arg = ""
  
          for char in args_str:
              if char == "[":
                  bracket_count += 1
              elif char == "]":
                  bracket_count -= 1
  
              if char == "," and bracket_count == 0:
                  args.append(current_arg.strip())
                  current_arg = ""
              else:
                  current_arg += char
  
          if current_arg:
              args.append(current_arg.strip())
  
          return args
  
      if "[" in type_str and type_str.endswith("]"):
          # Handle generics
          main_type_str, generics_str = type_str.split("[", 1)
          generics_str = generics_str[:-1]
  
          main_type = deserialize_type(main_type_str)
          generic_args = tuple(
              deserialize_type(arg)
              for arg in parse_generic_args(generics_str)
          )
  
          # Reconstruct
          return main_type[generic_args]
  
      else:
          # Handle non-generics
          parts = type_str.split(".")
          module_name = ".".join(parts[:-1]) or "builtins"
          type_name = parts[-1]
  
          module = sys.modules.get(module_name)
          if not module:
              try:
                  module = importlib.import_module(module_name)
              except ImportError as e:
                  raise DeserializationError(
                      f"Could not import the module: {module_name}"
                  ) from e
  
          deserialized_type = getattr(module, type_name, None)
          if not deserialized_type:
              raise DeserializationError(
                  f"Could not locate the type: {type_name} in the module: {module_name}"
              )
  
          return deserialized_type
  
imports: import importlib
  import inspect
  import sys
  from typing import Any, get_origin
  from haystack import DeserializationError
label_desc: Use image node_id 2 for calling a global function with example usage: deserialize_type(type_str) and returns: args, main_type, deserialized_type