mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-06 09:50:01 +00:00
Nicer error when packing a datetime without tzinfo (#466)
This commit is contained in:
parent
cfa05d3fdc
commit
e464cb44fa
3 changed files with 22 additions and 0 deletions
|
|
@ -285,6 +285,8 @@ cdef class Packer(object):
|
|||
o = self._default(o)
|
||||
default_used = 1
|
||||
continue
|
||||
elif self.datetime and PyDateTime_CheckExact(o):
|
||||
PyErr_Format(ValueError, b"can not serialize '%.200s' object where tzinfo=None", Py_TYPE(o).tp_name)
|
||||
else:
|
||||
PyErr_Format(TypeError, b"can not serialize '%.200s' object", Py_TYPE(o).tp_name)
|
||||
return ret
|
||||
|
|
|
|||
|
|
@ -874,6 +874,10 @@ class Packer(object):
|
|||
obj = self._default(obj)
|
||||
default_used = 1
|
||||
continue
|
||||
|
||||
if self._datetime and check(obj, _DateTime):
|
||||
raise ValueError("Cannot serialize %r where tzinfo=None" % (obj,))
|
||||
|
||||
raise TypeError("Cannot serialize %r" % (obj,))
|
||||
|
||||
def pack(self, obj):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue