code: def _format_rule_for_python_class(rule: _RuleType) -> str:
      pascal_case_name = _kebab_case_to_pascal_case(rule["name"])
      short_description = rule["short_description"]["text"]
      message_template = rule["message_strings"]["default"]["text"]
      field_names = [
          field_name
          for _, field_name, _, _ in string.Formatter().parse(
              message_template
          )
          if field_name is not None
      ]
      for field_name in field_names:
          assert isinstance(
              field_name, str
          ), f"Unexpected field type {type(field_name)} from {field_name}. "
          "Field name must be string.\nFull message template: {message_template}"
          assert (
              not field_name.isnumeric()
          ), f"Unexpected numeric field name {field_name}. "
          "Only keyword name formatting is supported.\nFull message template: {message_template}"
      message_arguments = ", ".join(field_names)
      message_arguments_assigned = ", ".join(
          [f"{field_name}={field_name}" for field_name in field_names]
      )
      return _PY_RULE_CLASS_TEMPLATE.format(
          pascal_case_name=pascal_case_name,
          short_description=short_description,
          message_template=repr(message_template),
          message_arguments=message_arguments,
          message_arguments_assigned=message_arguments_assigned,
      )
  
file_path: pytorch/tools/onnx/gen_diagnostics.py
imports: import argparse
  import os
  import string
  import subprocess
  import textwrap
  from typing import Any, Mapping, Sequence
  import yaml
  from torchgen import utils
  from torchgen.yaml_utils import YamlLoader
label_desc: Use image node_id 3 for calling a global function with example usage: _format_rule_for_python_class(rule) and returns: _PY_RULE_CLASS_TEMPLATE