docs: def _create_init(name, slots, defaults):
      """Create the __init__ function for an immutable object.
  
      Parameters
      ----------
      name : str
          The name of the immutable class.
      slots : iterable of str
          The __slots__ field from the class.
      defaults : dict or None
          The default values for the arguments to __init__.
  
      Returns
      -------
      init : callable
          The __init__ function for the new immutable class.
      """
      if any(s.startswith('__') for s in slots):
          raise TypeError(
              "immutable classes may not have slots that start with '__'",
          )
  
      # If we have no defaults, ignore all of this.
      kwdefaults = None
      if defaults is not None:
          hit_default = False
          _defaults = []  # positional defaults
          kwdefaults = {}  # kwonly defaults
          kwdefs = False
          for s in slots:
              if s not in defaults and hit_default:
                  raise SyntaxError(
                      'non-default argument follows default argument'
                  )
  
              if not kwdefs:
                  try:
                      # Try to grab the next default.
                      # Pop so that we know they were all consumed when we
                      # are done.
                      _defaults.append(defaults.pop(s))
                  except KeyError:
                      # Not in the dict, we haven't hit any defaults yet.
                      pass
                  else:
                      # We are now consuming default arguments.
                      hit_default = True
                  if s.startswith('*'):
                      if s in defaults:
                          raise TypeError(
                              'cannot set default for var args or var kwargs',
                          )
                      if not s.startswith('**'):
                          kwdefs = True
              else:
                  kwdefaults[s] = defaults.pop(s)
  
          if defaults:
              # We didn't consume all of the defaults.
              raise TypeError(
                  'default value for non-existent argument%s: %s' % (
                      's' if len(defaults) > 1 else '',
                      ', '.join(starmap('{0}={1!r}'.format, defaults.items())),
                  )
              )
  
          # cast back to tuples
          defaults = tuple(_defaults)
  
      if not slots:
          return _no_arg_init, ()
  
      ns = {'__initialize_slot': initialize_slot}
      # filter out lone star
      slotnames = tuple(filter(None, (s.strip('*') for s in slots)))
      # We are using exec here so that we can later inspect the call signature
      # of the __init__. This makes the positional vs keywords work as intended.
      # This is totally reasonable, no h8 m8!
      exec(
          'def __init__(_{name}__self, {args}):    \n    {assign}'.format(
              name=name,
              args=', '.join(slots),
              assign='\n    '.join(
                  map(
                      '__initialize_slot(_{1}__self, "{0}", {0})'.format,
                      slotnames,
                      repeat(name),
                  ),
              ),
          ),
          ns,
      )
      init = ns['__init__']
      init.__defaults__ = defaults
      init.__kwdefaults__ = kwdefaults
      return init, slotnames