class_docstr: Writes a single pyi file
class_docstr_tok: ["Writes","a","single","pyi","file"]
code: def write(self) -> str:
      # save current module content, so that imports and module docstring can be inserted
      saved_lines = self.lines
      self.lines = []
  
      # module docstring may exist as comment before syntax (optional) or package name
      if not self._write_comments(
          [d.FileDescriptorProto.PACKAGE_FIELD_NUMBER]
      ):
          self._write_comments(
              [d.FileDescriptorProto.SYNTAX_FIELD_NUMBER]
          )
  
      if self.lines:
          assert self.lines[0].startswith('"""')
          self.lines[0] = f'"""{HEADER}{self.lines[0][3:]}'
      else:
          self._write_line(f'"""{HEADER}"""')
  
      for reexport_idx in self.fd.public_dependency:
          reexport_file = self.fd.dependency[reexport_idx]
          reexport_fd = self.descriptors.files[reexport_file]
          reexport_imp = (
              reexport_file[:-6].replace("-", "_").replace("/", ".")
              + "_pb2"
          )
          names = (
              [m.name for m in reexport_fd.message_type]
              + [m.name for m in reexport_fd.enum_type]
              + [v.name for m in reexport_fd.enum_type for v in m.value]
              + [m.name for m in reexport_fd.extension]
          )
          if reexport_fd.options.py_generic_services:
              names.extend(m.name for m in reexport_fd.service)
  
          if names:
              # n,n to force a reexport (from x import y as y)
              self.from_imports[reexport_imp].update(
                  (n, n) for n in names
              )
  
      if self.typing_extensions_min:
          self.imports.add("sys")
      for pkg in sorted(self.imports):
          self._write_line(f"import {pkg}")
      if self.typing_extensions_min:
          self._write_line("")
          self._write_line(
              f"if sys.version_info >= {self.typing_extensions_min}:"
          )
          self._write_line("    import typing as typing_extensions")
          self._write_line("else:")
          self._write_line("    import typing_extensions")
  
      for pkg, items in sorted(self.from_imports.items()):
          self._write_line(f"from {pkg} import (")
          for name, reexport_name in sorted(items):
              if reexport_name is None:
                  self._write_line(f"    {name},")
              else:
                  self._write_line(f"    {name} as {reexport_name},")
          self._write_line(")")
      self._write_line("")
  
      # restore module content
      self.lines += saved_lines
  
      content = "\n".join(self.lines)
      if not content.endswith("\n"):
          content = content + "\n"
      return content
  
imports: from __future__ import annotations
  import sys
  from collections import defaultdict
  from contextlib import contextmanager
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Set, Sequence, Tuple
  import google.protobuf.descriptor_pb2
  from google.protobuf.compiler import plugin_pb2
  from google.protobuf.internal.containers import RepeatedCompositeFieldContainer
  from google.protobuf.internal.well_known_types import WKTBASES
  from .None import extensions_pb2
label_desc: Use image node_id 27 for calling the PkgWriter obj's underlying member method code with example usage: obj.write() and returns: content