def METHOD_NAME(self, o, slot, value):
    # Set a slot on the given object to value, doing a cast if
    # necessary. The value None is special-cased and never cast.
    cls = o.__class__.__slots__[slot]
    if value is not None:
        if isinstance(value, bytes):
            value = value.decode('utf-8')
        value = cls(value)
    setattr(o, slot, value)