Skip to content

Commit f322ed4

Browse files
committed
Merge pull request #84 from wbolster/exception-type-cleanups
Always raise TypeError for wrong argument types
2 parents 7973cce + 77046b8 commit f322ed4

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

msgpack/_unpacker.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ cdef inline init_ctx(unpack_context *ctx,
5252
ctx.user.object_hook = ctx.user.list_hook = <PyObject*>NULL
5353

5454
if object_hook is not None and object_pairs_hook is not None:
55-
raise ValueError("object_pairs_hook and object_hook are mutually exclusive.")
55+
raise TypeError("object_pairs_hook and object_hook are mutually exclusive.")
5656

5757
if object_hook is not None:
5858
if not PyCallable_Check(object_hook):
@@ -228,7 +228,7 @@ cdef class Unpacker(object):
228228
if file_like:
229229
self.file_like_read = file_like.read
230230
if not PyCallable_Check(self.file_like_read):
231-
raise ValueError("`file_like.read` must be a callable.")
231+
raise TypeError("`file_like.read` must be a callable.")
232232
if not max_buffer_size:
233233
max_buffer_size = INT_MAX
234234
if read_size > max_buffer_size:

msgpack/fallback.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
159159
self._fb_feeding = True
160160
else:
161161
if not callable(file_like.read):
162-
raise ValueError("`file_like.read` must be callable")
162+
raise TypeError("`file_like.read` must be callable")
163163
self.file_like = file_like
164164
self._fb_feeding = False
165165
self._fb_buffers = []
@@ -179,16 +179,16 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
179179
self._ext_hook = ext_hook
180180

181181
if list_hook is not None and not callable(list_hook):
182-
raise ValueError('`list_hook` is not callable')
182+
raise TypeError('`list_hook` is not callable')
183183
if object_hook is not None and not callable(object_hook):
184-
raise ValueError('`object_hook` is not callable')
184+
raise TypeError('`object_hook` is not callable')
185185
if object_pairs_hook is not None and not callable(object_pairs_hook):
186-
raise ValueError('`object_pairs_hook` is not callable')
186+
raise TypeError('`object_pairs_hook` is not callable')
187187
if object_hook is not None and object_pairs_hook is not None:
188-
raise ValueError("object_pairs_hook and object_hook are mutually "
189-
"exclusive")
188+
raise TypeError("object_pairs_hook and object_hook are mutually "
189+
"exclusive")
190190
if not callable(ext_hook):
191-
raise ValueError("`ext_hook` is not callable")
191+
raise TypeError("`ext_hook` is not callable")
192192

193193
def feed(self, next_bytes):
194194
if isinstance(next_bytes, array.array):

test/test_obj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_decode_pairs_hook():
3131
assert unpacked[1] == prod_sum
3232

3333
def test_only_one_obj_hook():
34-
with raises(ValueError):
34+
with raises(TypeError):
3535
unpackb(b'', object_hook=lambda x: x, object_pairs_hook=lambda x: x)
3636

3737
def test_bad_hook():

0 commit comments

Comments
 (0)