Skip to content
Snippets Groups Projects
Commit f862b8a9a814 authored by ijl's avatar ijl
Browse files

Simplify default fallthrough

parent eeefbc0e7566
No related branches found
No related tags found
No related merge requests found
......@@ -56,8 +56,8 @@
self.ptr,
std::ptr::null_mut() as *mut pyo3::ffi::PyObject
));
if default_obj.is_null() {
if unlikely!(default_obj.is_null()) {
err!(format_args!(
"Type is not JSON serializable: {}",
obj_name!(ob_type!(self.ptr))
))
......@@ -60,12 +60,7 @@
err!(format_args!(
"Type is not JSON serializable: {}",
obj_name!(ob_type!(self.ptr))
))
} else if !ffi!(PyErr_Occurred()).is_null() {
err!(format_args!(
"Type raised exception in default function: {}",
obj_name!(ob_type!(self.ptr))
))
} else {
let res = SerializePyObject::new(
default_obj,
......
......@@ -27,7 +27,7 @@
// test_uuid_overflow
pyo3::ffi::_PyLong_AsByteArray(
py_int as *mut pyo3::ffi::PyLongObject,
buffer.as_ptr() as *const c_uchar,
buffer.as_ptr() as *mut c_uchar,
16,
1, // little_endian
0, // is_signed
......
arrow
dataclasses;python_version<"3.7"
numpy;platform_machine=="x86_64" and python_version<"3.9"
pendulum;sys_platform=="linux" and python_version<"3.9" and platform_machine=="x86_64"
pendulum;sys_platform=="linux" and platform_machine=="x86_64"
psutil
pytest
pytz
......
......@@ -26,6 +26,10 @@
return obj.cur
def default_raises(obj):
raise TypeError
class TypeTests(unittest.TestCase):
def test_default_not_callable(self):
"""
......@@ -95,6 +99,15 @@
ran = True
self.assertTrue(ran)
def test_default_exception_type(self):
"""
dumps() TypeError in default() raises orjson.JSONEncodeError
"""
ref = Custom()
with self.assertRaises(orjson.JSONEncodeError):
orjson.dumps(ref, default=default_raises)
def test_default_func_nested_str(self):
"""
dumps() default function nested str
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment