code: def _make_class_swappable(cls: Type[C], **kwargs) -> Type[C]:
      """
      Creates a new class that subclasses ModularComponent.
  
      Modifies that class to to accept constructors for the components passed to the
      decorator.
      """
  
      def _class_dict(new_fields) -> Dict[str, Any]:
          """
          Sets up the class attributes, along with type annotations.
          """
          return {
              **new_fields,
              "__annotations__": {
                  **{k: type(v) for k, v in new_fields.items()}
              },
          }
  
      # Create SwappableSubcomponents dataclass with components passed to @swappable
      subcomponent_class_name = (
          ModularComponent.SwappableSubcomponents.__name__
      )
      subcomponent_dataclass = dataclass(
          type(subcomponent_class_name, (), _class_dict(kwargs))
      )
  
      # Create a new class that subclasses the decorated class. This new class holds
      # the SwappableSubcomponents dataclass created above (list of components that are
      # swappable) and the swappables attribute (the actual swappable component constructors).
      return type(
          # We append "_Swappable" to the new class name for transparency.
          f"{cls.__name__}_Swappable",
          # ModularComponent comes before the class so we can intercept __init__ calls.
          (ModularComponent, cls),  # type: ignore
          # Items in this dictionary are converted to class attributes by type()
          _class_dict(
              {subcomponent_class_name: subcomponent_dataclass}
          ),
      )
  
file_path: ParlAI/parlai/agents/transformer/modules/modular.py
imports: from __future__ import annotations
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, Generic, Optional, Type, TypeVar
label_desc: Use image node_id 2 for calling a global function with example usage: _make_class_swappable(cls) and returns: type, dict