From: Markus Armbruster <armbru@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>,
Fam Zheng <famz@redhat.com>,
qemu-devel@nongnu.org, wenchaoqemu@gmail.com
Subject: Re: [Qemu-devel] [PATCH v4 08/19] qapi: Better error messages for bad expressions
Date: Fri, 26 Sep 2014 13:40:57 +0200 [thread overview]
Message-ID: <87fvfeehiu.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <20140926092516.GA4068@noname.redhat.com> (Kevin Wolf's message of "Fri, 26 Sep 2014 11:25:16 +0200")
Kevin Wolf <kwolf@redhat.com> writes:
> Am 26.09.2014 um 11:15 hat Markus Armbruster geschrieben:
>> Kevin Wolf <kwolf@redhat.com> writes:
>>
>> > Am 24.09.2014 um 09:34 hat Markus Armbruster geschrieben:
>> >> Eric Blake <eblake@redhat.com> writes:
>> >>
>> >> > On 09/23/2014 08:56 AM, Markus Armbruster wrote:
>> >> >> Eric Blake <eblake@redhat.com> 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 <eblake@redhat.com>
>> >> >>
>> >> >
>> >> >>> +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.
>>
>> I think there are two sane ways forward:
>>
>> 1. Declare QAPI schemas to be ASCII only for now. Replace the one
>> instance of basestring by plain str.
>>
>> 2. Fix the code to work with both ASCII and Unicode strings even in
>> Python 2. Package six could be used.
>>
>> I'm voting for 1.
>
> As I said, the problem is probably not about the actual value of the
> string (I doubt we use anything but ASCII at the moment), but about its
> type. We may need to convert something somewhere. If you think it's
> worth the effort of finding that place, go ahead.
A value always has a concrete type. I'd expect all string values in the
qapi scripts to be of type str.
We have to mess with Python 2's basestring only where we need to cope
with string values that may be either of type str or of type unicode.
Since there should not be any values of type unicode, I don't see why
we'd want to do the extra work required for 2.
next prev parent reply other threads:[~2014-09-26 11:41 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 22:24 [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 01/19] qapi: Consistent whitespace in tests/Makefile Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 02/19] qapi: Ignore files created during make check Eric Blake
2014-09-23 8:07 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 03/19] qapi: Update docs given recent event, spacing fixes Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 04/19] qapi: Document type-safety considerations Eric Blake
2014-09-22 12:37 ` Markus Armbruster
2014-09-22 16:53 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 05/19] qapi: Add some enum tests Eric Blake
2014-09-22 12:43 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 06/19] qapi: Better error messages for bad enums Eric Blake
2014-09-23 14:23 ` Markus Armbruster
2014-09-23 15:59 ` Eric Blake
2014-09-24 7:46 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 07/19] qapi: Add some expr tests Eric Blake
2014-09-23 14:26 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 08/19] qapi: Better error messages for bad expressions Eric Blake
2014-09-23 14:56 ` Markus Armbruster
2014-09-23 16:11 ` Eric Blake
2014-09-24 7:34 ` Markus Armbruster
2014-09-24 9:25 ` Kevin Wolf
2014-09-24 11:14 ` Markus Armbruster
2014-09-26 9:15 ` Markus Armbruster
2014-09-26 9:25 ` Kevin Wolf
2014-09-26 11:40 ` Markus Armbruster [this message]
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 09/19] qapi: Add tests of redefined expressions Eric Blake
2014-09-24 11:24 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 10/19] qapi: Better error messages for duplicated expressions Eric Blake
2014-09-24 11:58 ` Markus Armbruster
2014-09-24 14:10 ` Eric Blake
2014-09-24 15:29 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 11/19] qapi: Add tests of type bypass Eric Blake
2014-09-24 16:10 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 7:34 ` Markus Armbruster
2014-09-25 8:06 ` Markus Armbruster
2014-09-25 14:00 ` Eric Blake
2014-09-25 16:19 ` Markus Armbruster
2015-03-23 15:33 ` [Qemu-devel] RFC: 'alternate' qapi top-level expression [was: [PATCH v4 12/19] qapi: Add some type check tests] Eric Blake
2015-03-23 19:28 ` Markus Armbruster
2014-09-25 13:54 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 16:12 ` Markus Armbruster
2014-09-25 16:32 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 13/19] qapi: More rigourous checking of types Eric Blake
2014-09-26 9:26 ` Markus Armbruster
2014-09-29 8:27 ` Markus Armbruster
2014-09-29 14:26 ` Eric Blake
2014-09-29 14:35 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 14/19] qapi: More rigorous checking for type safety bypass Eric Blake
2014-09-29 8:38 ` Markus Armbruster
2014-09-29 14:33 ` Eric Blake
2014-09-29 16:35 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 15/19] qapi: Merge UserDefTwo and UserDefNested in tests Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 16/19] qapi: Drop tests for inline subtypes Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 17/19] qapi: Drop inline subtype in query-version Eric Blake
2014-09-30 17:40 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 18/19] qapi: Drop inline subtype in query-pci Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 19/19] qapi: Drop support for inline subtypes Eric Blake
2014-09-30 17:47 ` Markus Armbruster
2014-09-26 15:42 ` [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fvfeehiu.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wenchaoqemu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.