def setattr(self, target, name, value=notset, raising=True):
__tracebackhide__ = True<EOL>import inspect<EOL>if value is notset:<EOL><INDENT>if not isinstance(target, six.string_types):<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>value = name<EOL>name, target = derive_importpath(target, raising)<EOL><DEDENT>oldval = getattr(target, name, notset)<EOL>if raising and oldval is notset:<EOL><INDENT>raise AttributeError("<STR_LIT>" % (target, name))<EOL><DEDENT>if inspect.isclass(target):<EOL><INDENT>oldval = target.__dict__.get(name, notset)<EOL><DEDENT>self._setattr.append((target, name, oldval))<EOL>setattr(target, name, value)<EOL>
Set attribute value on target, memorizing the old value.
        By default raise AttributeError if the attribute did not exist.

        For convenience you can specify a string as ``target`` which
        will be interpreted as a dotted import path, with the last part
        being the attribute name.  Example:
        ``monkeypatch.setattr("os.getcwd", lambda: "/")``
        would set the ``getcwd`` function of the ``os`` module.

        The ``raising`` value determines if the setattr should fail
        if the attribute is not already present (defaults to True
        which means it will raise).