should check that key is a str as well (it's a bug that write() doesn't)