From 77046b839da20feb528d303c8858ab6f34013ce7 Mon Sep 17 00:00:00 2001 From: Wouter Bolsterlee Date: Tue, 11 Feb 2014 20:34:23 +0100 Subject: Always raise TypeError for wrong argument types The code that checks whether hooks are callable() (and some other type checks) should always raise TypeError on failure. Before this change, both ValueError and TypeError were used in an inconsistent way (C extension and Python implementation were not the same). --- msgpack/_unpacker.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'msgpack/_unpacker.pyx') diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx index d5aa46e..18592f4 100644 --- a/msgpack/_unpacker.pyx +++ b/msgpack/_unpacker.pyx @@ -52,7 +52,7 @@ cdef inline init_ctx(unpack_context *ctx, ctx.user.object_hook = ctx.user.list_hook = NULL if object_hook is not None and object_pairs_hook is not None: - raise ValueError("object_pairs_hook and object_hook are mutually exclusive.") + raise TypeError("object_pairs_hook and object_hook are mutually exclusive.") if object_hook is not None: if not PyCallable_Check(object_hook): @@ -227,7 +227,7 @@ cdef class Unpacker(object): if file_like: self.file_like_read = file_like.read if not PyCallable_Check(self.file_like_read): - raise ValueError("`file_like.read` must be a callable.") + raise TypeError("`file_like.read` must be a callable.") if not max_buffer_size: max_buffer_size = INT_MAX if read_size > max_buffer_size: -- cgit v1.2.1