Skip to contentSkip to conversation

qapi: cleanup redundant variable

PATCH In review Amos Kong 3 participants 3 messages Jan 23, 2014 – Feb 3, 2014

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 qapi: cleanup redundant variable

No need to re-append an expr list, it's ok to return schema.exprs

---
 scripts/qapi.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
scripts/qapi.py +1 -4
index 7b92689..718f1ad 100644
@@ -175,8 +175,6 @@ def parse_schema(fp):
         print >>sys.stderr, e
         exit(1)
 
-    exprs = []
-
     for expr in schema.exprs:
         if expr.has_key('enum'):
             add_enum(expr['enum'])
@@ -185,9 +183,8 @@ def parse_schema(fp):
             add_enum('%sKind' % expr['union'])
         elif expr.has_key('type'):
             add_struct(expr)
-        exprs.append(expr)
 
-    return exprs
+    return schema.exprs
 
 def parse_args(typeinfo):
     if isinstance(typeinfo, basestring):
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 21 lines · Amos Kong

No need to re-append an expr list, it's ok to return schema.exprs

---
 scripts/qapi.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
scripts/qapi.py +0 -2
index 7b92689..718f1ad 100644
@@ -175,8 +175,6 @@ def parse_schema(fp):
         print >>sys.stderr, e
         exit(1)
 
-    exprs = []
-
     for expr in schema.exprs:
         if expr.has_key('enum'):
             add_enum(expr['enum'])

scripts/qapi.py def parse_schema(fp): · line 187

Quoted 7 lines
scripts/qapi.py +1 -2
@@ -185,9 +183,8 @@ def parse_schema(fp):
             add_enum('%sKind' % expr['union'])
         elif expr.has_key('type'):
             add_struct(expr)
-        exprs.append(expr)
 
-    return exprs
+    return schema.exprs

I don't really know python. Does it mean that previously, this function returned a copy of schema.exprs, but now it returns schema.exprs itself, so a caller can modify it?

Thanks,

/mjt

#2 lore raw
Quoted 14 lines · Michael Tokarev
Quoted 13 lines · Amos Kong

No need to re-append an expr list, it's ok to return schema.exprs

---
 scripts/qapi.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
scripts/qapi.py +0 -1
@@ -185,9 +183,8 @@ def parse_schema(fp):
             add_enum('%sKind' % expr['union'])
         elif expr.has_key('type'):
             add_struct(expr)
-        exprs.append(expr)
 
Quoted 6 lines

scripts/qapi.py def parse_schema(fp): · line 187

Quoted 2 lines
scripts/qapi.py +1 -1
-    return exprs
+    return schema.exprs

I don't really know python. Does it mean that previously, this function returned a copy of schema.exprs, but now it returns schema.exprs itself, so a caller can modify it?

My python is also weak (hence my lack of R-b), but yes, I believe you are correct. On the other hand, parse_schema is only called up front, so I don't think callers are modifying the return value anyways, so does it matter?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org