qapi: Bye-bye Python 2
cover qapi: Bye-bye Python 2
Markus Armbruster (4):
qapi: Inheriting from object is pointless with Python 3, drop
qapi: Drop conditionals for Python 2
qapi: Use super() now we have Python 3
qapi: Brush off some (py)lint
scripts/qapi/commands.py | 6 +-- scripts/qapi/common.py | 6 +-- scripts/qapi/error.py | 4 +- scripts/qapi/events.py | 4 +- scripts/qapi/expr.py | 3 +- scripts/qapi/gen.py | 27 +++++++------ scripts/qapi/introspect.py | 6 +-- scripts/qapi/parser.py | 20 ++++------ scripts/qapi/schema.py | 71 +++++++++++++++++----------------- scripts/qapi/source.py | 4 +- scripts/qapi/types.py | 4 +- scripts/qapi/visit.py | 4 +- tests/qapi-schema/test-qapi.py | 6 +-- 13 files changed, 73 insertions(+), 92 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/4 qapi: Inheriting from object is pointless with Python 3, drop
--- scripts/qapi/gen.py | 2 +- scripts/qapi/parser.py | 6 +++--- scripts/qapi/schema.py | 12 ++++++------ scripts/qapi/source.py | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-)
scripts/qapi/gen.py +1 -1
@@ -22,7 +22,7 @@ from qapi.common import * from qapi.schema import QAPISchemaVisitor -class QAPIGen(object): +class QAPIGen: def __init__(self, fname): self.fname = fname
scripts/qapi/parser.py +3 -3
@@ -23,7 +23,7 @@ from qapi.error import QAPIParseError, QAPISemError from qapi.source import QAPISourceInfo -class QAPISchemaParser(object): +class QAPISchemaParser: def __init__(self, fname, previously_included=None, incl_info=None): previously_included = previously_included or set()
@@ -293,7 +293,7 @@ class QAPISchemaParser(object): raise QAPIParseError(self, "documentation comment must end with '##'") -class QAPIDoc(object): +class QAPIDoc: """ A documentation comment block, either definition or free-form
@@ -312,7 +312,7 @@ class QAPIDoc(object): Free-form documentation blocks consist only of a body section. """ - class Section(object): + class Section: def __init__(self, name=None): # optional section name (argument/member or section name) self.name = name
scripts/qapi/schema.py +6 -6
@@ -24,7 +24,7 @@ from qapi.expr import check_exprs from qapi.parser import QAPISchemaParser -class QAPISchemaEntity(object): +class QAPISchemaEntity: meta = None def __init__(self, name, info, doc, ifcond=None, features=None):
@@ -89,7 +89,7 @@ class QAPISchemaEntity(object): return "%s '%s'" % (self.meta, self.name) -class QAPISchemaVisitor(object): +class QAPISchemaVisitor: def visit_begin(self, schema): pass
@@ -135,7 +135,7 @@ class QAPISchemaVisitor(object): pass -class QAPISchemaModule(object): +class QAPISchemaModule: def __init__(self, name): self.name = name self._entity_list = []
@@ -441,7 +441,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.features) -class QAPISchemaMember(object): +class QAPISchemaMember: """ Represents object members, enum members and features """ role = 'member'
@@ -519,7 +519,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): self.describe) -class QAPISchemaObjectTypeVariants(object): +class QAPISchemaObjectTypeVariants: def __init__(self, tag_name, info, tag_member, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name.
@@ -787,7 +787,7 @@ class QAPISchemaEvent(QAPISchemaEntity): self.arg_type, self.boxed) -class QAPISchema(object): +class QAPISchema: def __init__(self, fname): self.fname = fname parser = QAPISchemaParser(fname)
scripts/qapi/source.py +2 -2
@@ -13,7 +13,7 @@ import copy import sys -class QAPISchemaPragma(object): +class QAPISchemaPragma: def __init__(self): # Are documentation comments required? self.doc_required = False
@@ -23,7 +23,7 @@ class QAPISchemaPragma(object): self.name_case_whitelist = [] -class QAPISourceInfo(object): +class QAPISourceInfo: def __init__(self, fname, line, parent): self.fname = fname self.line = line
Signature · 1 line
2.21.1
Re: [PATCH 1/4] qapi: Inheriting from object is pointless with Python 3, drop
Quoted 125 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/gen.py | 2 +- scripts/qapi/parser.py | 6 +++--- scripts/qapi/schema.py | 12 ++++++------ scripts/qapi/source.py | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-)scripts/qapi/gen.py +1
-1@@ -22,7 +22,7 @@ from qapi.common import * from qapi.schema import QAPISchemaVisitor -class QAPIGen(object): +class QAPIGen: def __init__(self, fname): self.fname = fnamescripts/qapi/parser.py +3
-3@@ -23,7 +23,7 @@ from qapi.error import QAPIParseError, QAPISemError from qapi.source import QAPISourceInfo -class QAPISchemaParser(object): +class QAPISchemaParser: def __init__(self, fname, previously_included=None, incl_info=None): previously_included = previously_included or set()@@ -293,7 +293,7 @@ class QAPISchemaParser(object): raise QAPIParseError(self, "documentation comment must end with '##'") -class QAPIDoc(object): +class QAPIDoc: """ A documentation comment block, either definition or free-form@@ -312,7 +312,7 @@ class QAPIDoc(object): Free-form documentation blocks consist only of a body section. """ - class Section(object): + class Section: def __init__(self, name=None): # optional section name (argument/member or section name) self.name = namescripts/qapi/schema.py +6
-6@@ -24,7 +24,7 @@ from qapi.expr import check_exprs from qapi.parser import QAPISchemaParser -class QAPISchemaEntity(object): +class QAPISchemaEntity: meta = None def __init__(self, name, info, doc, ifcond=None, features=None):@@ -89,7 +89,7 @@ class QAPISchemaEntity(object): return "%s '%s'" % (self.meta, self.name) -class QAPISchemaVisitor(object): +class QAPISchemaVisitor: def visit_begin(self, schema): pass@@ -135,7 +135,7 @@ class QAPISchemaVisitor(object): pass -class QAPISchemaModule(object): +class QAPISchemaModule: def __init__(self, name): self.name = name self._entity_list = []@@ -441,7 +441,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.features) -class QAPISchemaMember(object): +class QAPISchemaMember: """ Represents object members, enum members and features """ role = 'member'@@ -519,7 +519,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): self.describe) -class QAPISchemaObjectTypeVariants(object): +class QAPISchemaObjectTypeVariants: def __init__(self, tag_name, info, tag_member, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name.@@ -787,7 +787,7 @@ class QAPISchemaEvent(QAPISchemaEntity): self.arg_type, self.boxed) -class QAPISchema(object): +class QAPISchema: def __init__(self, fname): self.fname = fname parser = QAPISchemaParser(fname)scripts/qapi/source.py +1
-1@@ -13,7 +13,7 @@ import copy import sys -class QAPISchemaPragma(object): +class QAPISchemaPragma: def __init__(self): # Are documentation comments required? self.doc_required = False
scripts/qapi/source.py class QAPISchemaPragma(object): · line 29
Quoted 8 lines
scripts/qapi/source.py +1
-1@@ -23,7 +23,7 @@ class QAPISchemaPragma(object): self.name_case_whitelist = [] -class QAPISourceInfo(object): +class QAPISourceInfo: def __init__(self, fname, line, parent): self.fname = fname self.line = line
PATCH 2/4 qapi: Drop conditionals for Python 2
In reply to Markus Armbruster--- scripts/qapi/common.py | 6 +----- scripts/qapi/gen.py | 6 +----- scripts/qapi/parser.py | 6 +----- tests/qapi-schema/test-qapi.py | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-)
scripts/qapi/common.py +1 -5
@@ -12,7 +12,6 @@ # See the COPYING file in the top-level directory. import re -import string # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1
@@ -43,10 +42,7 @@ def c_enum_const(type_name, const_name, prefix=None): return camel_to_upper(type_name) + '_' + c_name(const_name, False).upper() -if hasattr(str, 'maketrans'): - c_name_trans = str.maketrans('.-', '__') -else: - c_name_trans = string.maketrans('.-', '__') +c_name_trans = str.maketrans('.-', '__') # Map @name to a valid C identifier.
scripts/qapi/gen.py +1 -5
@@ -15,7 +15,6 @@ import errno import os import re -import sys from contextlib import contextmanager from qapi.common import *
@@ -54,10 +53,7 @@ class QAPIGen: if e.errno != errno.EEXIST: raise fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666) - if sys.version_info[0] >= 3: - f = open(fd, 'r+', encoding='utf-8') - else: - f = os.fdopen(fd, 'r+') + f = open(fd, 'r+', encoding='utf-8') text = self.get_content() oldtext = f.read(len(text) + 1) if text != oldtext:
scripts/qapi/parser.py +1 -5
@@ -16,7 +16,6 @@ import os import re -import sys from collections import OrderedDict from qapi.error import QAPIParseError, QAPISemError
@@ -30,10 +29,7 @@ class QAPISchemaParser: previously_included.add(os.path.abspath(fname)) try: - if sys.version_info[0] >= 3: - fp = open(fname, 'r', encoding='utf-8') - else: - fp = open(fname, 'r') + fp = open(fname, 'r', encoding='utf-8') self.src = fp.read() except IOError as e: raise QAPISemError(incl_info or QAPISourceInfo(None, None, None),
tests/qapi-schema/test-qapi.py +1 -5
@@ -16,15 +16,11 @@ import argparse import difflib import os import sys +from io import StringIO from qapi.error import QAPIError from qapi.schema import QAPISchema, QAPISchemaVisitor -if sys.version_info[0] < 3: - from cStringIO import StringIO -else: - from io import StringIO - class QAPISchemaTestVisitor(QAPISchemaVisitor):
Signature · 1 line
2.21.1
Re: [PATCH 2/4] qapi: Drop conditionals for Python 2
Quoted 92 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 6 +----- scripts/qapi/gen.py | 6 +----- scripts/qapi/parser.py | 6 +----- tests/qapi-schema/test-qapi.py | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-)scripts/qapi/common.py +1
-5@@ -12,7 +12,6 @@ # See the COPYING file in the top-level directory. import re -import string # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1@@ -43,10 +42,7 @@ def c_enum_const(type_name, const_name, prefix=None): return camel_to_upper(type_name) + '_' + c_name(const_name, False).upper() -if hasattr(str, 'maketrans'): - c_name_trans = str.maketrans('.-', '__') -else: - c_name_trans = string.maketrans('.-', '__') +c_name_trans = str.maketrans('.-', '__') # Map @name to a valid C identifier.scripts/qapi/gen.py +1
-5@@ -15,7 +15,6 @@ import errno import os import re -import sys from contextlib import contextmanager from qapi.common import *@@ -54,10 +53,7 @@ class QAPIGen: if e.errno != errno.EEXIST: raise fd = os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666) - if sys.version_info[0] >= 3: - f = open(fd, 'r+', encoding='utf-8') - else: - f = os.fdopen(fd, 'r+') + f = open(fd, 'r+', encoding='utf-8') text = self.get_content() oldtext = f.read(len(text) + 1) if text != oldtext:scripts/qapi/parser.py +1
-5@@ -16,7 +16,6 @@ import os import re -import sys from collections import OrderedDict from qapi.error import QAPIParseError, QAPISemError@@ -30,10 +29,7 @@ class QAPISchemaParser: previously_included.add(os.path.abspath(fname)) try: - if sys.version_info[0] >= 3: - fp = open(fname, 'r', encoding='utf-8') - else: - fp = open(fname, 'r') + fp = open(fname, 'r', encoding='utf-8') self.src = fp.read() except IOError as e: raise QAPISemError(incl_info or QAPISourceInfo(None, None, None),tests/qapi-schema/test-qapi.py +1
-0@@ -16,15 +16,11 @@ import argparse import difflib import os import sys +from io import StringIO from qapi.error import QAPIError
tests/qapi-schema/test-qapi.py import argparse · line 26
Quoted 10 lines
tests/qapi-schema/test-qapi.py +0
-5from qapi.schema import QAPISchema, QAPISchemaVisitor -if sys.version_info[0] < 3: - from cStringIO import StringIO -else: - from io import StringIO - class QAPISchemaTestVisitor(QAPISchemaVisitor):
PATCH 3/4 qapi: Use super() now we have Python 3
In reply to Markus Armbruster--- scripts/qapi/commands.py | 4 +-- scripts/qapi/error.py | 4 +-- scripts/qapi/events.py | 4 +-- scripts/qapi/gen.py | 10 ++++---- scripts/qapi/introspect.py | 4 +-- scripts/qapi/parser.py | 2 +- scripts/qapi/schema.py | 50 +++++++++++++++++++------------------- scripts/qapi/types.py | 4 +-- scripts/qapi/visit.py | 4 +-- 9 files changed, 43 insertions(+), 43 deletions(-)
scripts/qapi/commands.py +2 -2
@@ -237,8 +237,8 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): def __init__(self, prefix): - QAPISchemaModularCVisitor.__init__( - self, prefix, 'qapi-commands', + super().__init__( + prefix, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', None, __doc__) self._regy = QAPIGenCCode(None) self._visited_ret_types = {}
scripts/qapi/error.py +2 -2
@@ -35,9 +35,9 @@ class QAPIParseError(QAPIError): col = (col + 7) % 8 + 1 else: col += 1 - QAPIError.__init__(self, parser.info, col, msg) + super().__init__(parser.info, col, msg) class QAPISemError(QAPIError): def __init__(self, info, msg): - QAPIError.__init__(self, info, None, msg) + super().__init__(info, None, msg)
scripts/qapi/events.py +2 -2
@@ -138,8 +138,8 @@ def gen_event_send(name, arg_type, boxed, event_enum_name, event_emit): class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): def __init__(self, prefix): - QAPISchemaModularCVisitor.__init__( - self, prefix, 'qapi-events', + super().__init__( + prefix, 'qapi-events', ' * Schema-defined QAPI/QMP events', None, __doc__) self._event_enum_name = c_name(prefix + 'QAPIEvent', protect=False) self._event_enum_members = []
scripts/qapi/gen.py +5 -5
@@ -82,7 +82,7 @@ def _wrap_ifcond(ifcond, before, after): class QAPIGenCCode(QAPIGen): def __init__(self, fname): - QAPIGen.__init__(self, fname) + super().__init__(fname) self._start_if = None def start_if(self, ifcond):
@@ -102,13 +102,13 @@ class QAPIGenCCode(QAPIGen): def get_content(self): assert self._start_if is None - return QAPIGen.get_content(self) + return super().get_content() class QAPIGenC(QAPIGenCCode): def __init__(self, fname, blurb, pydoc): - QAPIGenCCode.__init__(self, fname) + super().__init__(fname) self._blurb = blurb self._copyright = '\n * '.join(re.findall(r'^Copyright .*', pydoc, re.MULTILINE))
@@ -141,7 +141,7 @@ char qapi_dummy_%(name)s; class QAPIGenH(QAPIGenC): def _top(self): - return QAPIGenC._top(self) + guardstart(self.fname) + return super()._top() + guardstart(self.fname) def _bottom(self): return guardend(self.fname)
@@ -176,7 +176,7 @@ def ifcontext(ifcond, *args): class QAPIGenDoc(QAPIGen): def _top(self): - return (QAPIGen._top(self) + return (super()._top() + '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n')
scripts/qapi/introspect.py +2 -2
@@ -76,8 +76,8 @@ def to_c_string(string): class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): def __init__(self, prefix, unmask): - QAPISchemaMonolithicCVisitor.__init__( - self, prefix, 'qapi-introspect', + super().__init__( + prefix, 'qapi-introspect', ' * QAPI/QMP schema introspection', __doc__) self._unmask = unmask self._schema = None
scripts/qapi/parser.py +1 -1
@@ -320,7 +320,7 @@ class QAPIDoc: class ArgSection(Section): def __init__(self, name): - QAPIDoc.Section.__init__(self, name) + super().__init__(name) self.member = None def connect(self, member):
scripts/qapi/schema.py +25 -25
196 lines not on this page · raw message
scripts/qapi/types.py +2 -2
@@ -241,8 +241,8 @@ void qapi_free_%(c_name)s(%(c_name)s *obj) class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): def __init__(self, prefix): - QAPISchemaModularCVisitor.__init__( - self, prefix, 'qapi-types', ' * Schema-defined QAPI types', + super().__init__( + prefix, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) def _begin_system_module(self, name):
scripts/qapi/visit.py +2 -2
@@ -283,8 +283,8 @@ out: class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): def __init__(self, prefix): - QAPISchemaModularCVisitor.__init__( - self, prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', + super().__init__( + prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) def _begin_system_module(self, name):
Signature · 1 line
2.21.1
Re: [PATCH 3/4] qapi: Use super() now we have Python 3
Quoted 2 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>---
[...]
Quoted 4 lines
scripts/qapi/schema.py +0
-0
[...]
scripts/qapi/schema.py class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): · line 618
Quoted 7 lines
scripts/qapi/schema.py +1
-1@@ -614,7 +614,7 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role = 'branch' def __init__(self, name, info, typ, ifcond=None): - QAPISchemaObjectTypeMember.__init__(self, name, info, typ, + super().__init__(name, info, typ, False, ifcond)
pycodestyle-3 gripes:
scripts/qapi/schema.py:618:45: E127 continuation line over-indented for visual indent
Will fix.
[...]
PATCH 4/4 qapi: Brush off some (py)lint
In reply to Markus Armbruster--- scripts/qapi/commands.py | 2 +- scripts/qapi/expr.py | 3 +-- scripts/qapi/gen.py | 9 ++++++--- scripts/qapi/introspect.py | 2 -- scripts/qapi/parser.py | 6 ++---- scripts/qapi/schema.py | 9 ++++----- 6 files changed, 14 insertions(+), 17 deletions(-)
scripts/qapi/commands.py +1 -1
@@ -274,7 +274,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', - c_prefix=c_name(self._prefix, protect=False))) + c_prefix=c_name(self._prefix, protect=False))) self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-commands.h"
scripts/qapi/expr.py +1 -2
@@ -35,7 +35,6 @@ def check_name_is_str(name, info, source): def check_name_str(name, info, source, allow_optional=False, enum_member=False, permit_upper=False): - global valid_name membername = name if allow_optional and name.startswith('*'):
@@ -249,7 +248,7 @@ def check_union(expr, info): def check_alternate(expr, info): members = expr['data'] - if len(members) == 0: + if not members: raise QAPISemError(info, "'data' must not be empty") for (key, value) in members.items(): source = "'data' member '%s'" % key
scripts/qapi/gen.py +6 -3
@@ -45,10 +45,10 @@ class QAPIGen: def write(self, output_dir): pathname = os.path.join(output_dir, self.fname) - dir = os.path.dirname(pathname) - if dir: + odir = os.path.dirname(pathname) + if odir: try: - os.makedirs(dir) + os.makedirs(odir) except os.error as e: if e.errno != errno.EEXIST: raise
@@ -261,6 +261,9 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): genc.write(output_dir) genh.write(output_dir) + def _begin_system_module(self, name): + pass + def _begin_user_module(self, name): pass
scripts/qapi/introspect.py +0 -2
@@ -10,8 +10,6 @@ This work is licensed under the terms of the GNU GPL, version 2. See the COPYING file in the top-level directory. """ -import string - from qapi.common import * from qapi.gen import QAPISchemaMonolithicCVisitor from qapi.schema import (QAPISchemaArrayType, QAPISchemaBuiltinType,
scripts/qapi/parser.py +2 -4
@@ -282,8 +282,7 @@ class QAPISchemaParser: doc.end_comment() self.accept() return doc - else: - doc.append(self.val) + doc.append(self.val) self.accept(False) raise QAPIParseError(self, "documentation comment must end with '##'")
@@ -492,7 +491,7 @@ class QAPIDoc: raise QAPIParseError(self._parser, "'%s' can't follow '%s' section" % (name, self.sections[0].name)) - elif self._is_section_tag(name): + if self._is_section_tag(name): line = line[len(name)+1:] self._start_section(name[:-1])
@@ -556,7 +555,6 @@ class QAPIDoc: raise QAPISemError(feature.info, "feature '%s' lacks documentation" % feature.name) - self.features[feature.name] = QAPIDoc.ArgSection(feature.name) self.features[feature.name].connect(feature) def check_expr(self, expr):
scripts/qapi/schema.py +4 -5
@@ -19,7 +19,7 @@ import re from collections import OrderedDict from qapi.common import c_name, pointer_suffix -from qapi.error import QAPIError, QAPIParseError, QAPISemError +from qapi.error import QAPIError, QAPISemError from qapi.expr import check_exprs from qapi.parser import QAPISchemaParser
@@ -96,14 +96,14 @@ class QAPISchemaVisitor: def visit_end(self): pass - def visit_module(self, fname): + def visit_module(self, name): pass def visit_needed(self, entity): # Default to visiting everything return True - def visit_include(self, fname, info): + def visit_include(self, name, info): pass def visit_builtin_type(self, name, info, json_type):
@@ -576,7 +576,7 @@ class QAPISchemaObjectTypeVariants: assert self.tag_member.ifcond == [] if self._tag_name: # flat union # branches that are not explicitly covered get an empty type - cases = set([v.name for v in self.variants]) + cases = {v.name for v in self.variants} for m in self.tag_member.type.members: if m.name not in cases: v = QAPISchemaObjectTypeVariant(m.name, self.info,
@@ -1098,7 +1098,6 @@ class QAPISchema: def visit(self, visitor): visitor.visit_begin(self) - module = None for mod in self._module_dict.values(): mod.visit(visitor) visitor.visit_end()
Signature · 1 line
2.21.1
Re: [PATCH 4/4] qapi: Brush off some (py)lint
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>
I wrote some pylint cleanup for iotests recently, too. Are you targeting a subset of pylint errors to clean here?
(Do any files pass 100%?)
Consider checking in a pylintrc file that lets others run the same subset of pylint tests as you are doing so that we can prevent future regressions.
Take a peek at [PATCH v6 0/9] iotests: use python logging
Thanks for this series. I had a very similar series sitting waiting to go out, but this goes further in a few places.
--js
Quoted 163 lines
--- scripts/qapi/commands.py | 2 +- scripts/qapi/expr.py | 3 +-- scripts/qapi/gen.py | 9 ++++++--- scripts/qapi/introspect.py | 2 -- scripts/qapi/parser.py | 6 ++---- scripts/qapi/schema.py | 9 ++++----- 6 files changed, 14 insertions(+), 17 deletions(-)scripts/qapi/commands.py +1
-1@@ -274,7 +274,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', - c_prefix=c_name(self._prefix, protect=False))) + c_prefix=c_name(self._prefix, protect=False))) self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-commands.h"scripts/qapi/expr.py +1
-2@@ -35,7 +35,6 @@ def check_name_is_str(name, info, source): def check_name_str(name, info, source, allow_optional=False, enum_member=False, permit_upper=False): - global valid_name membername = name if allow_optional and name.startswith('*'):@@ -249,7 +248,7 @@ def check_union(expr, info): def check_alternate(expr, info): members = expr['data'] - if len(members) == 0: + if not members: raise QAPISemError(info, "'data' must not be empty") for (key, value) in members.items(): source = "'data' member '%s'" % keyscripts/qapi/gen.py +6
-3@@ -45,10 +45,10 @@ class QAPIGen: def write(self, output_dir): pathname = os.path.join(output_dir, self.fname) - dir = os.path.dirname(pathname) - if dir: + odir = os.path.dirname(pathname) + if odir: try: - os.makedirs(dir) + os.makedirs(odir) except os.error as e: if e.errno != errno.EEXIST: raise@@ -261,6 +261,9 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): genc.write(output_dir) genh.write(output_dir) + def _begin_system_module(self, name): + pass + def _begin_user_module(self, name): passscripts/qapi/introspect.py +0
-2@@ -10,8 +10,6 @@ This work is licensed under the terms of the GNU GPL, version 2. See the COPYING file in the top-level directory. """ -import string - from qapi.common import * from qapi.gen import QAPISchemaMonolithicCVisitor from qapi.schema import (QAPISchemaArrayType, QAPISchemaBuiltinType,scripts/qapi/parser.py +2
-4@@ -282,8 +282,7 @@ class QAPISchemaParser: doc.end_comment() self.accept() return doc - else: - doc.append(self.val) + doc.append(self.val) self.accept(False) raise QAPIParseError(self, "documentation comment must end with '##'")@@ -492,7 +491,7 @@ class QAPIDoc: raise QAPIParseError(self._parser, "'%s' can't follow '%s' section" % (name, self.sections[0].name)) - elif self._is_section_tag(name): + if self._is_section_tag(name): line = line[len(name)+1:] self._start_section(name[:-1])@@ -556,7 +555,6 @@ class QAPIDoc: raise QAPISemError(feature.info, "feature '%s' lacks documentation" % feature.name) - self.features[feature.name] = QAPIDoc.ArgSection(feature.name) self.features[feature.name].connect(feature) def check_expr(self, expr):scripts/qapi/schema.py +4
-5@@ -19,7 +19,7 @@ import re from collections import OrderedDict from qapi.common import c_name, pointer_suffix -from qapi.error import QAPIError, QAPIParseError, QAPISemError +from qapi.error import QAPIError, QAPISemError from qapi.expr import check_exprs from qapi.parser import QAPISchemaParser@@ -96,14 +96,14 @@ class QAPISchemaVisitor: def visit_end(self): pass - def visit_module(self, fname): + def visit_module(self, name): pass def visit_needed(self, entity): # Default to visiting everything return True - def visit_include(self, fname, info): + def visit_include(self, name, info): pass def visit_builtin_type(self, name, info, json_type):@@ -576,7 +576,7 @@ class QAPISchemaObjectTypeVariants: assert self.tag_member.ifcond == [] if self._tag_name: # flat union # branches that are not explicitly covered get an empty type - cases = set([v.name for v in self.variants]) + cases = {v.name for v in self.variants} for m in self.tag_member.type.members: if m.name not in cases: v = QAPISchemaObjectTypeVariant(m.name, self.info,@@ -1098,7 +1098,6 @@ class QAPISchema: def visit(self, visitor): visitor.visit_begin(self) - module = None for mod in self._module_dict.values(): mod.visit(visitor) visitor.visit_end()
Signature · 1 line
—js
Re: [PATCH 4/4] qapi: Brush off some (py)lint
Quoted 7 lines · John Snow
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>I wrote some pylint cleanup for iotests recently, too. Are you targeting a subset of pylint errors to clean here?
(Do any files pass 100%?)
Surely you're joking, Mr. Snow!
I'm chipping away at pylint's gripes. I ran it with the following messages disabled:
bad-whitespace,
fixme,
invalid-name,
missing-docstring,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-lines,
too-many-locals,
too-many-statements,
unused-argument,
unused-wildcard-import,
These are not all obviously useless. They're just not what I want to focus on right now.
Remaining:
1 x C0330: Wrong continued indentation (remove 19 spaces).
Accident, will fix in v2.
8 x R0201: Method could be a function (no-self-use)
Yes, but the override in a sub-class does use self.
2 x W0212: Access to a protected member _body of a client class (protected-access)
Needs cleanup, but not now.
6 x W0401: Wildcard import qapi.common (wildcard-import)
Not sure I care. I'd prefer not to have more wildcard imports, though.
2 x W0603: Using the global statement (global-statement)
Cleanup is non-trivial. Not now.
I also ran pycodestyle-3:
1 x E127 continuation line over-indented for visual indent
Same as pylint's C0330, will fix in v2.
3 x E261 at least two spaces before inline comment
I blame Emacs. Left for another day.
8 x E501 line too long
Left for another day.
1 x E713 test for membership should be 'not in'
I missed that one, will fix in v2.
Quoted 3 lines
Consider checking in a pylintrc file that lets others run the same subset of pylint tests as you are doing so that we can prevent future regressions.
Working towards it, slowly.
Quoted 4 lines
Take a peek at [PATCH v6 0/9] iotests: use python logging
Thanks for this series. I had a very similar series sitting waiting to go out, but this goes further in a few places.
Thanks!
Re: [PATCH 4/4] qapi: Brush off some (py)lint
Quoted 29 lines · Markus Armbruster
Quoted 7 lines · John Snow
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>I wrote some pylint cleanup for iotests recently, too. Are you targeting a subset of pylint errors to clean here?
(Do any files pass 100%?)
Surely you're joking, Mr. Snow!
I'm chipping away at pylint's gripes. I ran it with the following messages disabled:
bad-whitespace,
fixme,
invalid-name,
missing-docstring,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-lines,
too-many-locals,
too-many-statements,
unused-argument,
unused-wildcard-import,
Quoted 3 lines
These are not all obviously useless. They're just not what I want to focus on right now.
Yes, understood - so my approach is disable what I don't intend to fix, commit the pylintrc to prevent backslide, and move on.
I think we have a difference in what a pylintrc means to us (the goal vs. the current status.)
I didn't mean "100% without caveats", just "100% in some subset of checks".
(I assume the answer is still no.)
Quoted 54 lines
Remaining:
1 x C0330: Wrong continued indentation (remove 19 spaces).
Accident, will fix in v2.
8 x R0201: Method could be a function (no-self-use)
Yes, but the override in a sub-class does use self.
2 x W0212: Access to a protected member
_bodyof a client class (protected-access)Needs cleanup, but not now.
6 x W0401: Wildcard import qapi.common (wildcard-import)
Not sure I care. I'd prefer not to have more wildcard imports, though.
2 x W0603: Using the global statement (global-statement)
Cleanup is non-trivial. Not now.
I also ran pycodestyle-3:
1 x E127 continuation line over-indented for visual indent
Same as pylint's C0330, will fix in v2.
3 x E261 at least two spaces before inline comment
I blame Emacs. Left for another day.
8 x E501 line too long
Left for another day.
1 x E713 test for membership should be 'not in'
I missed that one, will fix in v2.
Quoted 3 lines
Consider checking in a pylintrc file that lets others run the same subset of pylint tests as you are doing so that we can prevent future regressions.
Working towards it, slowly.
Quoted 4 lines
Take a peek at [PATCH v6 0/9] iotests: use python logging
Thanks for this series. I had a very similar series sitting waiting to go out, but this goes further in a few places.
Thanks!
Re: [PATCH 4/4] qapi: Brush off some (py)lint
Quoted 37 lines · John Snow
Quoted 29 lines · Markus Armbruster
Quoted 7 lines · John Snow
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>I wrote some pylint cleanup for iotests recently, too. Are you targeting a subset of pylint errors to clean here?
(Do any files pass 100%?)
Surely you're joking, Mr. Snow!
I'm chipping away at pylint's gripes. I ran it with the following messages disabled:
bad-whitespace,
fixme,
invalid-name,
missing-docstring,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-lines,
too-many-locals,
too-many-statements,
unused-argument,
unused-wildcard-import,Quoted 3 lines
These are not all obviously useless. They're just not what I want to focus on right now.
Yes, understood - so my approach is disable what I don't intend to fix, commit the pylintrc to prevent backslide, and move on.
Quoted 6 lines
I think we have a difference in what a pylintrc means to us (the goal vs. the current status.)
I didn't mean "100% without caveats", just "100% in some subset of checks".
(I assume the answer is still no.)
To turn the answer into a yes, I'd have to disable the messages below, and some of them I'd rather keep.
Tacking
# pylint: disable=...
to existing troublemakers may or may not be worth the ugliness (it needs to go on the same line, which almost invariably makes it awkwardly long).
Quoted 54 lines
Quoted 54 lines
Remaining:
1 x C0330: Wrong continued indentation (remove 19 spaces).
Accident, will fix in v2.
8 x R0201: Method could be a function (no-self-use)
Yes, but the override in a sub-class does use self.
2 x W0212: Access to a protected member
_bodyof a client class (protected-access)Needs cleanup, but not now.
6 x W0401: Wildcard import qapi.common (wildcard-import)
Not sure I care. I'd prefer not to have more wildcard imports, though.
2 x W0603: Using the global statement (global-statement)
Cleanup is non-trivial. Not now.
I also ran pycodestyle-3:
1 x E127 continuation line over-indented for visual indent
Same as pylint's C0330, will fix in v2.
3 x E261 at least two spaces before inline comment
I blame Emacs. Left for another day.
8 x E501 line too long
Left for another day.
1 x E713 test for membership should be 'not in'
I missed that one, will fix in v2.
Quoted 3 lines
Consider checking in a pylintrc file that lets others run the same subset of pylint tests as you are doing so that we can prevent future regressions.
Working towards it, slowly.
Quoted 4 lines
Take a peek at [PATCH v6 0/9] iotests: use python logging
Thanks for this series. I had a very similar series sitting waiting to go out, but this goes further in a few places.
Thanks!