class_docstr: Writes a single pyi file
class_docstr_tok: ["Writes","a","single","pyi","file"]
code: def write_messages(
      self, messages: List[d.DescriptorProto], prefix: str
  ) -> None:
      line = self._write_line
      message_class = self._import("google.protobuf.message", "Message")
  
      for desc in messages:
          self.locals.add(desc.name)
          qualified_name = prefix + desc.name
          line("class {}({}):", desc.name, message_class)
          with self._indent():
              # Nested enums/messages
              self.write_enums(desc.enum_type)
              self.write_messages(
                  desc.nested_type, qualified_name + "."
              )
  
              # Scalar fields
              for field in [f for f in desc.field if is_scalar(f)]:
                  if (
                      field.label
                      == d.FieldDescriptorProto.LABEL_REPEATED
                  ):
                      container = self._import(
                          "google.protobuf.internal.containers",
                          "RepeatedScalarFieldContainer",
                      )
                      line(
                          "{} = ... # type: {}[{}]",
                          field.name,
                          container,
                          self.python_type(field),
                      )
                  else:
                      line(
                          "{} = ... # type: {}",
                          field.name,
                          self.python_type(field),
                      )
              line("")
  
              # Getters for non-scalar fields
              for field in [f for f in desc.field if not is_scalar(f)]:
                  line("@property")
                  if (
                      field.label
                      == d.FieldDescriptorProto.LABEL_REPEATED
                  ):
                      msg = self.descriptors.messages[field.type_name]
                      if msg.options.map_entry:
                          # map generates a special Entry wrapper message
                          container = self._import(
                              "typing", "MutableMapping"
                          )
                          line(
                              "def {}(self) -> {}[{}, {}]: ...",
                              field.name,
                              container,
                              self.python_type(msg.field[0]),
                              self.python_type(msg.field[1]),
                          )
                      else:
                          container = self._import(
                              "google.protobuf.internal.containers",
                              "RepeatedCompositeFieldContainer",
                          )
                          line(
                              "def {}(self) -> {}[{}]: ...",
                              field.name,
                              container,
                              self.python_type(field),
                          )
                  else:
                      line(
                          "def {}(self) -> {}: ...",
                          field.name,
                          self.python_type(field),
                      )
                  line("")
  
              # Constructor
              line("def __init__(self,")
              with self._indent():
                  # Required args
                  for field in [
                      f
                      for f in desc.field
                      if f.label
                      == d.FieldDescriptorProto.LABEL_REQUIRED
                  ]:
                      line(
                          "{} : {},",
                          field.name,
                          self.python_type(field),
                      )
                  for field in [
                      f
                      for f in desc.field
                      if f.label
                      != d.FieldDescriptorProto.LABEL_REQUIRED
                  ]:
                      if (
                          field.label
                          == d.FieldDescriptorProto.LABEL_REPEATED
                      ):
                          if (
                              field.type_name != ""
                              and self.descriptors.messages[
                                  field.type_name
                              ].options.map_entry
                          ):
                              msg = self.descriptors.messages[
                                  field.type_name
                              ]
                              line(
                                  "{} : {}[{}[{}, {}]] = None,",
                                  field.name,
                                  self._import(
                                      "typing",
                                      "Optional",
                                      "OptionalType",
                                  ),
                                  self._import("typing", "Mapping"),
                                  self.python_type(msg.field[0]),
                                  self.python_type(msg.field[1]),
                              )
                          else:
                              line(
                                  "{} : {}[{}[{}]] = None,",
                                  field.name,
                                  self._import(
                                      "typing",
                                      "Optional",
                                      "OptionalType",
                                  ),
                                  self._import("typing", "Iterable"),
                                  self.python_type(field),
                              )
                      else:
                          line(
                              "{} : {}[{}] = None,",
                              field.name,
                              self._import(
                                  "typing", "Optional", "OptionalType"
                              ),
                              self.python_type(field),
                          )
                  line(") -> None: ...")
  
              # Standard message methods
              line("@classmethod")
              line(
                  "def FromString(cls, s: bytes) -> {}: ...",
                  qualified_name,
              )
              line(
                  "def MergeFrom(self, other_msg: {}) -> None: ...",
                  message_class,
              )
              line(
                  "def CopyFrom(self, other_msg: {}) -> None: ...",
                  message_class,
              )
          line("")
  
file_path: onnx/tools/protoc-gen-mypy.py
imports: import sys
  from collections import defaultdict
  from contextlib import contextmanager
  from typing import Any, Callable, Dict, Generator, List, Optional, Set, cast
label_desc: Use image node_id 7 for calling the PkgWriter obj's underlying member method code with example usage: obj.write_messages(messages, prefix) without return types