parameters: (message_descriptor, cls)
docstring: Adds an __init__ method to cls.
docstring_summary: Adds an __init__ method to cls.
docstring_tokens: Adds an __init__ method to cls .
function: def _AddInitMethod(message_descriptor, cls):
    """Adds an __init__ method to cls."""
    fields = message_descriptor.fields
    def init(self, **kwargs):
      self._cached_byte_size = 0
      self._cached_byte_size_dirty = len(kwargs) > 0
      self._fields = {}
      # _unknown_fields is () when empty for efficiency, and will be turned into
      # a list if fields are added.
      self._unknown_fields = ()
      self._is_present_in_parent = False
      self._listener = message_listener_mod.NullMessageListener()
      self._listener_for_children = _Listener(self)
      for field_name, field_value in kwargs.iteritems():
        field = _GetFieldByName(message_descriptor, field_name)
        if field is None:
          raise TypeError("%s() got an unexpected keyword argument '%s'" %
                          (message_descriptor.name, field_name))
        if field.label == _FieldDescriptor.LABEL_REPEATED:
          copy = field._default_constructor(self)
          if field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:  # Composite
            for val in field_value:
              copy.add().MergeFrom(val)
          else:  # Scalar
            copy.extend(field_value)
          self._fields[field] = copy
        elif field.cpp_type == _FieldDescriptor.CPPTYPE_MESSAGE:
          copy = field._default_constructor(self)
          copy.MergeFrom(field_value)
          self._fields[field] = copy
        else:
          setattr(self, field_name, field_value)
  
    init.__module__ = None
    init.__doc__ = None
    cls.__init__ = init
function_tokens: def _AddInitMethod ( message_descriptor , cls ) : fields = message_descriptor . fields def init ( self , * * kwargs ) : self . _cached_byte_size = 0 self . _cached_byte_size_dirty = len ( kwargs ) > 0 self . _fields = { } # _unknown_fields is () when empty for efficiency, and will be turned into # a list if fields are added. self . _unknown_fields = ( ) self . _is_present_in_parent = False self . _listener = message_listener_mod . NullMessageListener ( ) self . _listener_for_children = _Listener ( self ) for field_name , field_value in kwargs . iteritems ( ) : field = _GetFieldByName ( message_descriptor , field_name ) if field is None : raise TypeError ( "%s() got an unexpected keyword argument '%s'" % ( message_descriptor . name , field_name ) ) if field . label == _FieldDescriptor . LABEL_REPEATED : copy = field . _default_constructor ( self ) if field . cpp_type == _FieldDescriptor . CPPTYPE_MESSAGE : # Composite for val in field_value : copy . add ( ) . MergeFrom ( val ) else : # Scalar copy . extend ( field_value ) self . _fields [ field ] = copy elif field . cpp_type == _FieldDescriptor . CPPTYPE_MESSAGE : copy = field . _default_constructor ( self ) copy . MergeFrom ( field_value ) self . _fields [ field ] = copy else : setattr ( self , field_name , field_value ) init . __module__ = None init . __doc__ = None cls . __init__ = init