@@ -251,7 +251,7 @@ cdef class Unpacker(object):
251
251
252
252
def __init__ (self , file_like = None , Py_ssize_t read_size = 0 , bint use_list = 1 ,
253
253
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 ,
255
255
object ext_hook = ExtType,
256
256
Py_ssize_t max_str_len = 2147483647 , # 2**32-1
257
257
Py_ssize_t max_bin_len = 2147483647 ,
@@ -289,15 +289,19 @@ cdef class Unpacker(object):
289
289
if encoding is not None :
290
290
if isinstance (encoding, unicode ):
291
291
self .encoding = encoding.encode(' ascii' )
292
- else :
292
+ elif isinstance (encoding, bytes) :
293
293
self .encoding = encoding
294
+ else :
295
+ raise TypeError (" encoding should be bytes or unicode" )
294
296
cenc = PyBytes_AsString(self .encoding)
295
297
296
298
if unicode_errors is not None :
297
299
if isinstance (unicode_errors, unicode ):
298
300
self .unicode_errors = unicode_errors.encode(' ascii' )
299
- else :
301
+ elif isinstance (encoding, bytes)
300
302
self .unicode_errors = unicode_errors
303
+ else :
304
+ raise TypeError (" unicode_errors should be bytes or unicode" )
301
305
cerr = PyBytes_AsString(self .unicode_errors)
302
306
303
307
init_ctx(& self .ctx, object_hook, object_pairs_hook, list_hook,
0 commit comments