code: def serialize_type(target: Any) -> str:
      """
      Serializes a type or an instance to its string representation, including the module name.
  
      This function handles types, instances of types, and special typing objects.
      It assumes that non-typing objects will have a '__name__' attribute and raises
      an error if a type cannot be serialized.
  
      :param target: The object to serialize, can be an instance or a type.
      :type target: Any
      :return: The string representation of the type.
      :raises ValueError: If the type cannot be serialized.
      """
      # If the target is a string and contains a dot, treat it as an already serialized type
      if isinstance(target, str) and "." in target:
          return target
  
      # Determine if the target is a type or an instance of a typing object
      is_type_or_typing = isinstance(target, type) or bool(
          get_origin(target)
      )
      type_obj = target if is_type_or_typing else type(target)
      module = inspect.getmodule(type_obj)
      type_obj_repr = repr(type_obj)
  
      if type_obj_repr.startswith("typing."):
          # e.g., typing.List[int] -> List[int], we'll add the module below
          type_name = type_obj_repr.split(".", 1)[1]
      elif hasattr(type_obj, "__name__"):
          type_name = type_obj.__name__
      else:
          # If type cannot be serialized, raise an error
          raise ValueError(f"Could not serialize type: {type_obj_repr}")
  
      # Construct the full path with module name if available
      if module and hasattr(module, "__name__"):
          if module.__name__ == "builtins":
              # omit the module name for builtins, it just clutters the output
              # e.g. instead of 'builtins.str', we'll just return 'str'
              full_path = type_name
          else:
              full_path = f"{module.__name__}.{type_name}"
      else:
          full_path = type_name
  
      return full_path
  
imports: import importlib
  import inspect
  import sys
  from typing import Any, get_origin
  from haystack import DeserializationError
label_desc: Use image node_id 1 for calling a global function with example usage: serialize_type(target) and returns: full_path, target