I will add comments into the source code to explain. Basically if a native str or bool is supplied this method will return it quoted, this will effectively catch both Python 2 and Python 3's native str, however with python 2 this method will also catch the unicode type (text_type) and encode it to utf8, the use of six.text_type is entirely to prevent a syntax error in python 3 for an unknown type.