Merge "Explicitly raise ValueError in to_primitive"
This commit is contained in:
commit
2a29a5e836
@ -167,7 +167,7 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
|
||||
# __iter__ defined but it isn't callable as list().
|
||||
return six.text_type(value)
|
||||
|
||||
return value
|
||||
raise ValueError("Cannot convert %r to primitive" % (value,))
|
||||
|
||||
|
||||
JSONEncoder = json.JSONEncoder
|
||||
|
@ -254,7 +254,7 @@ class ToPrimitiveTestCase(test_base.BaseTestCase):
|
||||
self.assertEqual(dict(b=1),
|
||||
jsonutils.to_primitive(x, convert_instances=True))
|
||||
|
||||
self.assertEqual(x, jsonutils.to_primitive(x))
|
||||
self.assertRaises(ValueError, jsonutils.to_primitive, x)
|
||||
|
||||
def test_typeerror(self):
|
||||
x = bytearray # Class, not instance
|
||||
|
Loading…
x
Reference in New Issue
Block a user