diff mbox

[v5,03/28] qapi: Require ASCII in schema

Message ID 1427227433-5030-4-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake March 24, 2015, 8:03 p.m. UTC
Python 2 and Python 3 have a wild history of whether strings
default to ascii or unicode, where Python 3 requires checking
instanceof(foo, basestr) to cover all strings, but where that
code is not portable to Python 2.  It's simpler to just state
that we don't care about Unicode strings, and to just always
use the simpler instanceof(foo, str) everywhere.

I'm no python expert, so I'm basing it on this conversation:
https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg05278.html

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Eric Blake March 24, 2015, 8:33 p.m. UTC | #1
On 03/24/2015 02:03 PM, Eric Blake wrote:
> Python 2 and Python 3 have a wild history of whether strings
> default to ascii or unicode, where Python 3 requires checking
> instanceof(foo, basestr) to cover all strings, but where that
> code is not portable to Python 2.  It's simpler to just state
> that we don't care about Unicode strings, and to just always
> use the simpler instanceof(foo, str) everywhere.

And for all my proof-reading, I already have a commit message change:

s/instanceof/isinstance/

(you can tell I'm not that proficient in python...)

> 
> I'm no python expert, so I'm basing it on this conversation:
> https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg05278.html
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  scripts/qapi.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 

> @@ -354,7 +354,7 @@ def parse_schema(input_file):
>      return exprs
> 
>  def parse_args(typeinfo):
> -    if isinstance(typeinfo, basestring):
> +    if isinstance(typeinfo, str):

at least the code is right.
Markus Armbruster March 26, 2015, 9:54 a.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> On 03/24/2015 02:03 PM, Eric Blake wrote:
>> Python 2 and Python 3 have a wild history of whether strings
>> default to ascii or unicode, where Python 3 requires checking
>> instanceof(foo, basestr) to cover all strings, but where that
>> code is not portable to Python 2.  It's simpler to just state
>> that we don't care about Unicode strings, and to just always
>> use the simpler instanceof(foo, str) everywhere.
>
> And for all my proof-reading, I already have a commit message change:
>
> s/instanceof/isinstance/
>
> (you can tell I'm not that proficient in python...)
>
>> 
>> I'm no python expert, so I'm basing it on this conversation:
>> https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg05278.html
>> 
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>> ---
>>  scripts/qapi.py | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>
>> @@ -354,7 +354,7 @@ def parse_schema(input_file):
>>      return exprs
>> 
>>  def parse_args(typeinfo):
>> -    if isinstance(typeinfo, basestring):
>> +    if isinstance(typeinfo, str):
>
> at least the code is right.

Yup.  With the spelling fix:

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index d470347..20ee505 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -2,7 +2,7 @@ 
 # QAPI helper library
 #
 # Copyright IBM, Corp. 2011
-# Copyright (c) 2013 Red Hat Inc.
+# Copyright (c) 2013-2015 Red Hat Inc.
 #
 # Authors:
 #  Anthony Liguori <aliguori@us.ibm.com>
@@ -354,7 +354,7 @@  def parse_schema(input_file):
     return exprs

 def parse_args(typeinfo):
-    if isinstance(typeinfo, basestring):
+    if isinstance(typeinfo, str):
         struct = find_struct(typeinfo)
         assert struct != None
         typeinfo = struct['data']