@@ -251,7 +251,7 @@ cdef class Unpacker(object):
251251
252252 def __init__ (self , file_like = None , Py_ssize_t read_size = 0 , bint use_list = 1 ,
253253 object object_hook = None , object object_pairs_hook = None , object list_hook = None ,
254- str encoding = None , str unicode_errors = ' strict' , int max_buffer_size = 0 ,
254+ encoding = None , unicode_errors = ' strict' , int max_buffer_size = 0 ,
255255 object ext_hook = ExtType,
256256 Py_ssize_t max_str_len = 2147483647 , # 2**32-1
257257 Py_ssize_t max_bin_len = 2147483647 ,
@@ -289,15 +289,19 @@ cdef class Unpacker(object):
289289 if encoding is not None :
290290 if isinstance (encoding, unicode ):
291291 self .encoding = encoding.encode(' ascii' )
292- else :
292+ elif isinstance (encoding, bytes) :
293293 self .encoding = encoding
294+ else :
295+ raise TypeError (" encoding should be bytes or unicode" )
294296 cenc = PyBytes_AsString(self .encoding)
295297
296298 if unicode_errors is not None :
297299 if isinstance (unicode_errors, unicode ):
298300 self .unicode_errors = unicode_errors.encode(' ascii' )
299- else :
301+ elif isinstance (encoding, bytes)
300302 self .unicode_errors = unicode_errors
303+ else :
304+ raise TypeError (" unicode_errors should be bytes or unicode" )
301305 cerr = PyBytes_AsString(self .unicode_errors)
302306
303307 init_ctx(& self .ctx, object_hook, object_pairs_hook, list_hook,
0 commit comments