Have you tested this out? I don't think that creating the unicode object like this will work if `s` is a non-ASCII byte string, because it will try to decode it with ASCII encoding by default (causing a UnicodeDecode error). If `s` here is actually a unicode object to begin with, in which case you can just do `s.encode()`.