From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWkWp-0002BG-OH for qemu-devel@nongnu.org; Wed, 24 Sep 2014 07:14:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XWkWl-0004Ow-E0 for qemu-devel@nongnu.org; Wed, 24 Sep 2014 07:14:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWkWl-0004O3-6c for qemu-devel@nongnu.org; Wed, 24 Sep 2014 07:14:31 -0400 From: Markus Armbruster References: <1411165504-18198-1-git-send-email-eblake@redhat.com> <1411165504-18198-9-git-send-email-eblake@redhat.com> <87tx3ygzbc.fsf@blackfin.pond.sub.org> <54219BB6.3070007@redhat.com> <87a95pa2u7.fsf@blackfin.pond.sub.org> <20140924092547.GA3862@noname.redhat.com> Date: Wed, 24 Sep 2014 13:14:20 +0200 In-Reply-To: <20140924092547.GA3862@noname.redhat.com> (Kevin Wolf's message of "Wed, 24 Sep 2014 11:25:47 +0200") Message-ID: <87a95p2rub.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v4 08/19] qapi: Better error messages for bad expressions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Fam Zheng , qemu-devel@nongnu.org, wenchaoqemu@gmail.com, Luiz Capitulino Kevin Wolf writes: > Am 24.09.2014 um 09:34 hat Markus Armbruster geschrieben: >> Eric Blake writes: >> >> > On 09/23/2014 08:56 AM, Markus Armbruster wrote: >> >> Eric Blake writes: >> >>> Add check_keys to cover these situations, and update testcases to >> >>> match. A couple other tests (enum-missing-data, indented-expr) had >> >>> to change since the validation added here occurs so early. >> >>> >> >>> While valid .json files won't trigger any of these cases, we might >> >>> as well be nicer to developers that make a typo while trying to add >> >>> new QAPI code. >> >>> >> >>> Signed-off-by: Eric Blake >> >> >> > >> >>> +def check_keys(expr_elem, meta, required, optional=[]): >> >>> + expr = expr_elem['expr'] >> >>> + info = expr_elem['info'] >> >>> + name = expr[meta] >> >> >> >> Caller ensures expr[meta] exists. Okay. >> >> >> >>> + if not isinstance(name, basestring): >> >> >> >> I'm a Python noob: why basestring and not str? >> > >> > Me too. No clue. Copy and paste from existing code. >> > http://git.qemu.org/?p=qemu.git;a=blob;f=scripts/qapi.py;h=77d46aa;hb=769188d3b#l361 >> >> Yes. It's our only use of basestring. Other places use isinstance(FOO, >> str). >> >> The basestring use comes from Kevin's commit b35284e. Kevin, why >> basestring and not str? > > Do I look as if I knew what I'm doing when I write Python code? :-) > > Apparently basestring is the superclass for ASCII and Unicode strings. I > seem to dimly remember that I did indeed get a Unicode string somewhere > (even though probably no non-ASCII characters in it) and it caused > trouble. Might well have been here. Aha. These links apply: https://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility https://en.wikipedia.org/wiki/File:Pieter_Bruegel_the_Elder_%281568%29_The_Blind_Leading_the_Blind.jpg