提交 2ba699cb 编写于 作者: D Daniel P. Berrangé

python: avoid bare 'except:' clause

Exception catching statements should always match on a class name, the
most specific one possible. Rather than analyse the code to look at what
the most specific one is, this just uses the base Exception class.

docs/apibuild.py:255:9: E722 do not use bare 'except'
        except:
        ^
docs/apibuild.py:279:9: E722 do not use bare 'except'
        except:
        ^
...more...
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 cfdd871f
...@@ -887,14 +887,12 @@ FLAKE8_INDENTATION = E114,E115,E116,E121,E125,E126,E127,E128,E129,E131 ...@@ -887,14 +887,12 @@ FLAKE8_INDENTATION = E114,E115,E116,E121,E125,E126,E127,E128,E129,E131
FLAKE8_WHITESPACE = E211,E221,E222,E225,E226,E231,E261 FLAKE8_WHITESPACE = E211,E221,E222,E225,E226,E231,E261
FLAKE8_BLANK_LINES = E301,E302,E303,E305 FLAKE8_BLANK_LINES = E301,E302,E303,E305
FLAKE8_LINE_LENGTH = E501 FLAKE8_LINE_LENGTH = E501
FLAKE8_STATEMENTS = E722
FLAKE8_WARNINGS = W504 FLAKE8_WARNINGS = W504
FLAKE8_IGNORE = $(FLAKE8_INDENTATION),$\ FLAKE8_IGNORE = $(FLAKE8_INDENTATION),$\
$(FLAKE8_WHITESPACE),$\ $(FLAKE8_WHITESPACE),$\
$(FLAKE8_BLANK_LINES),$\ $(FLAKE8_BLANK_LINES),$\
$(FLAKE8_LINE_LENGTH),$\ $(FLAKE8_LINE_LENGTH),$\
$(FLAKE8_STATEMENTS),$\
$(FLAKE8_WARNINGS) \ $(FLAKE8_WARNINGS) \
$(NULL) $(NULL)
......
...@@ -252,7 +252,7 @@ class index: ...@@ -252,7 +252,7 @@ class index:
try: try:
d = self.identifiers[name] d = self.identifiers[name]
d.update(header, module, type, lineno, info, extra, conditionals) d.update(header, module, type, lineno, info, extra, conditionals)
except: except Exception:
d = identifier(name, header, module, type, lineno, info, extra, d = identifier(name, header, module, type, lineno, info, extra,
conditionals) conditionals)
self.identifiers[name] = d self.identifiers[name] = d
...@@ -276,7 +276,7 @@ class index: ...@@ -276,7 +276,7 @@ class index:
try: try:
d = self.identifiers[name] d = self.identifiers[name]
d.update(header, module, type, lineno, info, extra, conditionals) d.update(header, module, type, lineno, info, extra, conditionals)
except: except Exception:
d = identifier(name, header, module, type, lineno, info, extra, d = identifier(name, header, module, type, lineno, info, extra,
conditionals) conditionals)
self.identifiers[name] = d self.identifiers[name] = d
...@@ -784,7 +784,7 @@ class CParser: ...@@ -784,7 +784,7 @@ class CParser:
arg, desc = prefix.split(':', 1) arg, desc = prefix.split(':', 1)
desc = desc.strip() desc = desc.strip()
arg = arg.strip() arg = arg.strip()
except: except Exception:
if not quiet: if not quiet:
self.warning("Misformatted macro comment for %s" % name) self.warning("Misformatted macro comment for %s" % name)
self.warning(" problem with '%s'" % lines[0]) self.warning(" problem with '%s'" % lines[0])
...@@ -865,7 +865,7 @@ class CParser: ...@@ -865,7 +865,7 @@ class CParser:
arg, desc = prefix.split(':', 1) arg, desc = prefix.split(':', 1)
desc = desc.strip() desc = desc.strip()
arg = arg.strip() arg = arg.strip()
except: except Exception:
if not quiet: if not quiet:
self.warning("Misformatted function comment for %s" % name) self.warning("Misformatted function comment for %s" % name)
self.warning(" problem with '%s'" % lines[0]) self.warning(" problem with '%s'" % lines[0])
...@@ -908,7 +908,7 @@ class CParser: ...@@ -908,7 +908,7 @@ class CParser:
if len(line) >= 6 and line[0:7] == "Returns": if len(line) >= 6 and line[0:7] == "Returns":
try: try:
line = line.split(' ', 1)[1] line = line.split(' ', 1)[1]
except: except Exception:
line = "" line = ""
retdesc = line.strip() retdesc = line.strip()
del lines[0] del lines[0]
...@@ -976,7 +976,7 @@ class CParser: ...@@ -976,7 +976,7 @@ class CParser:
token = self.lexer.token() token = self.lexer.token()
try: try:
name = name.split('(') [0] name = name.split('(') [0]
except: except Exception:
pass pass
# skip hidden macros # skip hidden macros
...@@ -1016,7 +1016,7 @@ class CParser: ...@@ -1016,7 +1016,7 @@ class CParser:
self.defines.append(apstr) self.defines.append(apstr)
if apstr.find('ENABLED') != -1: if apstr.find('ENABLED') != -1:
self.conditionals.append("defined(%s)" % apstr) self.conditionals.append("defined(%s)" % apstr)
except: except Exception:
pass pass
elif name == "#ifndef": elif name == "#ifndef":
apstr = self.lexer.tokens[0][1] apstr = self.lexer.tokens[0][1]
...@@ -1024,7 +1024,7 @@ class CParser: ...@@ -1024,7 +1024,7 @@ class CParser:
self.defines.append(apstr) self.defines.append(apstr)
if apstr.find('ENABLED') != -1: if apstr.find('ENABLED') != -1:
self.conditionals.append("!defined(%s)" % apstr) self.conditionals.append("!defined(%s)" % apstr)
except: except Exception:
pass pass
elif name == "#if": elif name == "#if":
apstr = "" apstr = ""
...@@ -1036,7 +1036,7 @@ class CParser: ...@@ -1036,7 +1036,7 @@ class CParser:
self.defines.append(apstr) self.defines.append(apstr)
if apstr.find('ENABLED') != -1: if apstr.find('ENABLED') != -1:
self.conditionals.append(apstr) self.conditionals.append(apstr)
except: except Exception:
pass pass
elif name == "#else": elif name == "#else":
if self.conditionals != [] and \ if self.conditionals != [] and \
...@@ -1338,7 +1338,7 @@ class CParser: ...@@ -1338,7 +1338,7 @@ class CParser:
else: else:
try: try:
value = "%d" % (int(value) + 1) value = "%d" % (int(value) + 1)
except: except Exception:
self.warning("Failed to compute value of enum %s" % name) self.warning("Failed to compute value of enum %s" % name)
value = "" value = ""
if token[0] == "sep" and token[1] == ",": if token[0] == "sep" and token[1] == ",":
...@@ -1797,7 +1797,7 @@ class CParser: ...@@ -1797,7 +1797,7 @@ class CParser:
try: try:
if not CParser.long_legacy_functions[name][0]: if not CParser.long_legacy_functions[name][0]:
raise Exception() raise Exception()
except: except Exception:
self.error(("function '%s' is not allowed to return long, " self.error(("function '%s' is not allowed to return long, "
"use long long instead") % name) "use long long instead") % name)
...@@ -1806,7 +1806,7 @@ class CParser: ...@@ -1806,7 +1806,7 @@ class CParser:
try: try:
if param[1] not in CParser.long_legacy_functions[name][1]: if param[1] not in CParser.long_legacy_functions[name][1]:
raise Exception() raise Exception()
except: except Exception:
self.error(("function '%s' is not allowed to take long " self.error(("function '%s' is not allowed to take long "
"parameter '%s', use long long instead") "parameter '%s', use long long instead")
% (name, param[1])) % (name, param[1]))
...@@ -1826,7 +1826,7 @@ class CParser: ...@@ -1826,7 +1826,7 @@ class CParser:
try: try:
if field[1] not in CParser.long_legacy_struct_fields[name]: if field[1] not in CParser.long_legacy_struct_fields[name]:
raise Exception() raise Exception()
except: except Exception:
self.error(("struct '%s' is not allowed to contain long " self.error(("struct '%s' is not allowed to contain long "
"field '%s', use long long instead") "field '%s', use long long instead")
% (name, field[1])) % (name, field[1]))
...@@ -2101,7 +2101,7 @@ class docBuilder: ...@@ -2101,7 +2101,7 @@ class docBuilder:
try: try:
val = eval(info[0]) val = eval(info[0])
valhex = hex(val) valhex = hex(val)
except: except Exception:
val = info[0] val = info[0]
output.write(" value='%s'" % (val)) output.write(" value='%s'" % (val))
...@@ -2181,7 +2181,7 @@ class docBuilder: ...@@ -2181,7 +2181,7 @@ class docBuilder:
self.serialize_union(output, field, desc) self.serialize_union(output, field, desc)
else: else:
output.write(" <field name='%s' type='%s' info='%s'/>\n" % (field[1], field[0], desc)) output.write(" <field name='%s' type='%s' info='%s'/>\n" % (field[1], field[0], desc))
except: except Exception:
self.warning("Failed to serialize struct %s" % name) self.warning("Failed to serialize struct %s" % name)
output.write(" </struct>\n") output.write(" </struct>\n")
else: else:
...@@ -2196,7 +2196,7 @@ class docBuilder: ...@@ -2196,7 +2196,7 @@ class docBuilder:
output.write(" </typedef>\n") output.write(" </typedef>\n")
else: else:
output.write("/>\n") output.write("/>\n")
except: except Exception:
output.write("/>\n") output.write("/>\n")
def serialize_variable(self, output, name): def serialize_variable(self, output, name):
...@@ -2251,7 +2251,7 @@ class docBuilder: ...@@ -2251,7 +2251,7 @@ class docBuilder:
else: else:
output.write(" <arg name='%s' type='%s' info='%s'/>\n" % (param[1], param[0], escape(param[2]))) output.write(" <arg name='%s' type='%s' info='%s'/>\n" % (param[1], param[0], escape(param[2])))
self.indexString(name, param[2]) self.indexString(name, param[2])
except: except Exception:
print("Exception:", sys.exc_info()[1], file=sys.stderr) print("Exception:", sys.exc_info()[1], file=sys.stderr)
self.warning("Failed to save function %s info: %s" % (name, repr(id.info))) self.warning("Failed to save function %s info: %s" % (name, repr(id.info)))
output.write(" </%s>\n" % (id.type)) output.write(" </%s>\n" % (id.type))
...@@ -2331,7 +2331,7 @@ class docBuilder: ...@@ -2331,7 +2331,7 @@ class docBuilder:
funcs[param[0]].append(name) funcs[param[0]].append(name)
else: else:
funcs[param[0]] = [name] funcs[param[0]] = [name]
except: except Exception:
pass pass
typ = sorted(funcs.keys()) typ = sorted(funcs.keys())
for type in typ: for type in typ:
...@@ -2359,7 +2359,7 @@ class docBuilder: ...@@ -2359,7 +2359,7 @@ class docBuilder:
funcs[ret[0]].append(name) funcs[ret[0]].append(name)
else: else:
funcs[ret[0]] = [name] funcs[ret[0]] = [name]
except: except Exception:
pass pass
typ = sorted(funcs.keys()) typ = sorted(funcs.keys())
for type in typ: for type in typ:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册