Made write() exception clearer for unhandled types.

Made the exception in write() clearer when handling unsupported
types so that it now gives a more accurate TypeError instead of
a ValueError. Issue #153.