Thanks for your reply and i add check for one-element and 0-element. But seems this will make the code not succinct enough. V2: https://www.redhat.com/archives/libvir-list/2014-October/msg00815.html BTW,How about move the check to libvirt-override-virDomain.py? Thanks, Luyao Huang ----- Original Message ----- From: "Eric Blake" <eblake@xxxxxxxxxx> To: "Luyao Huang" <lhuang@xxxxxxxxxx>, libvir-list@xxxxxxxxxx Sent: Saturday, October 25, 2014 2:14:59 AM Subject: Re: [libvirt-python PATCH] Add a type check for time in libvirt_virDomainSetTime On 10/20/2014 03:43 AM, Luyao Huang wrote: > When pass a number or other things to setTime,no error output,but set time to 0. > Add a type check and give a clear error messages: > > TypeError: time must be dict > > Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx> > --- > libvirt-override.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/libvirt-override.c b/libvirt-override.c > index 9ba87eb..05552a7 100644 > --- a/libvirt-override.c > +++ b/libvirt-override.c > @@ -7795,6 +7795,11 @@ libvirt_virDomainSetTime(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { > return NULL; > domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); > > + if (!PyDict_Check(py_dict)) { > + PyErr_Format(PyExc_TypeError, "time must be dict"); > + return NULL; > + } What happens if py_dict is None or an empty dictionary? The code still does the wrong thing (it errors out if you have a one-element dictionary, but not if you have a 0-element dictionary); furthermore, we SHOULD allow a one-element dictionary (setting JUST seconds should do the sane thing of passing 0 for nseconds, instead of erroring out). Looking forward to v2. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list