The whole function is simply copied from https://github.com/nltk/nltk/blob/master/nltk/util.py#L712. Is there a reason `text_type` should be used there but not here?