code: def serialize_init_args(
      # pyre-fixme[2]: Parameter annotation cannot be `Any`.
      obj: Any,
      exclude_fields: Optional[List[str]] = None,
  ) -> Dict[str, Any]:
      """Given an object, return a dictionary of the arguments that are
      needed by its constructor.
      """
      properties = {}
      exclude_args = ["self", "args", "kwargs"] + (exclude_fields or [])
      signature = inspect.signature(obj.__class__.__init__)
      for arg in signature.parameters:
          if arg in exclude_args:
              continue
          try:
              value = getattr(obj, arg)
          except AttributeError:
              raise AttributeError(
                  f"{obj.__class__} is missing a value for {arg}, "
                  f"which is needed by its constructor."
              )
          properties[arg] = value
      return properties
  
file_path: Ax/ax/utils/common/serialization.py
imports: from __future__ import annotations
  import inspect
  import pydoc
  from types import FunctionType
  from typing import Any, Callable, Dict, List, Optional, Type
label_desc: Use image node_id 5 for calling a global function with example usage: serialize_init_args(obj, exclude_fields) and returns: properties