Rebase + squash + fixup of #814.

Is there a reason not to use self.__dict__.update(locals())?