def setthis(this, key, value):
    """Set attribute `key` on `this` to value and return `this`."""
    try:
        this.__dict__[key] = value
    except TypeError:
        setattr(this, key, value)
        return this
    else:
        return this
