code: def to_dataclass(
      cls: Any,
      base_cls: Optional[Any] = None,
      with_target: Optional[bool] = None,
      map_args: Optional[Dict[str, Tuple]] = None,
      exclude_args: Optional[List[str]] = None,
      strict: bool = False,
  ) -> Any:
      r"""Converts the input arguments of a given class :obj:`cls` to a
      :obj:`dataclass` schema.
  
      For example,
  
      .. code-block:: python
  
          from torch_geometric.transforms import NormalizeFeatures
  
          dataclass = to_dataclass(NormalizeFeatures)
  
      will generate
  
      .. code-block:: python
  
          @dataclass
          class NormalizeFeatures:
              _target_: str = "torch_geometric.transforms.NormalizeFeatures"
              attrs: List[str] = field(default_factory = lambda: ["x"])
  
      Args:
          cls (Any): The class to generate a schema for.
          base_cls (Any, optional): The base class of the schema.
              (default: :obj:`None`)
          with_target (bool, optional): If set to :obj:`False`, will not add the
              :obj:`_target_` attribute to the schema. If set to :obj:`None`,
              will only add the :obj:`_target_` in case :obj:`base_cls` is given.
              (default: :obj:`None`)
          map_args (Dict[str, Tuple], optional): Arguments for which annotation
              and default values should be overridden. (default: :obj:`None`)
          exclude_args (List[str or int], optional): Arguments to exclude.
              (default: :obj:`None`)
          strict (bool, optional): If set to :obj:`True`, ensures that all
              arguments in both :obj:`map_args` and :obj:`exclude_args` are
              present in the input parameters. (default: :obj:`False`)
      """
      fields = []
  
      params = inspect.signature(cls.__init__).parameters
  
      if (
          strict
      ):  # Check that keys in map_args or exclude_args are present.
          keys = set() if map_args is None else set(map_args.keys())
          if exclude_args is not None:
              keys |= set(
                  [arg for arg in exclude_args if isinstance(arg, str)]
              )
          diff = keys - set(params.keys())
          if len(diff) > 0:
              raise ValueError(
                  f"Expected input argument(s) {diff} in "
                  f"'{cls.__name__}'"
              )
  
      for i, (name, arg) in enumerate(params.items()):
          if name in EXCLUDE:
              continue
          if exclude_args is not None:
              if name in exclude_args or i in exclude_args:
                  continue
          if base_cls is not None:
              if name in base_cls.__dataclass_fields__:
                  continue
  
          if map_args is not None and name in map_args:
              fields.append((name,) + map_args[name])
              continue
  
          annotation, default = arg.annotation, arg.default
          annotation = map_annotation(annotation, mapping=MAPPING)
  
          if annotation != inspect.Parameter.empty:
              # `Union` types are not supported (except for `Optional`).
              # As such, we replace them with either `Any` or `Optional[Any]`.
              origin = getattr(annotation, "__origin__", None)
              args = getattr(annotation, "__args__", [])
              if (
                  origin == Union
                  and type(None) in args
                  and len(args) > 2
              ):
                  annotation = Optional[Any]
              elif origin == Union and type(None) not in args:
                  annotation = Any
              elif origin == list:
                  if getattr(args[0], "__origin__", None) == Union:
                      annotation = List[Any]
              elif origin == dict:
                  if getattr(args[1], "__origin__", None) == Union:
                      annotation = Dict[args[0], Any]  # type: ignore
          else:
              annotation = Any
  
          if str(default) == "<required parameter>":
              # Fix `torch.optim.SGD.lr = _RequiredParameter()`:
              # https://github.com/pytorch/hydra-torch/blob/main/
              # hydra-configs-torch/hydra_configs/torch/optim/sgd.py
              default = field(default=MISSING)
          elif default != inspect.Parameter.empty:
              if isinstance(default, (list, dict)):
                  # Avoid late binding of default values inside a loop:
                  # https://stackoverflow.com/questions/3431676/
                  # creating-functions-in-a-loop
                  def wrapper(default: Any) -> Callable[[], Any]:
                      return lambda: default
  
                  default = field(default_factory=wrapper(default))
          else:
              default = field(default=MISSING)
  
          fields.append((name, annotation, default))
  
      with_target = (
          base_cls is not None if with_target is None else with_target
      )
      if with_target:
          full_cls_name = f"{cls.__module__}.{cls.__qualname__}"
          fields.append(("_target_", str, field(default=full_cls_name)))
  
      return make_dataclass(
          cls.__qualname__,
          fields=fields,
          bases=() if base_cls is None else (base_cls,),
      )
  
file_path: pytorch_geometric/torch_geometric/config_store.py
imports: import copy
  import inspect
  import typing
  from collections import defaultdict
  from dataclasses import dataclass, field, make_dataclass
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: to_dataclass(cls, base_cls, with_target, map_args, exclude_args, strict) and returns: make_dataclass, function