We weren't closing the file descriptors from mkstemp, which caused fun
segmentation faults for me. This should fix the issue.
Fixes #5618
cc @y-p and @jseabold
I went ahead and simplifed all the prefixing stuff to just change a
single prefix_key function instead and handled the dynamic docstring
by setting the __doc__ attribute of functions/classes. set_o…