summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-12-24 17:05:37 -0500
committerJon Dufresne <jon.dufresne@gmail.com>2018-12-24 17:17:09 -0500
commitdf9b2d50b75ee42663195058f3112e6c440381c5 (patch)
treee7f9404d6d5675308f61e5f26acaaced6e66557f
parent7ee59bf9bec777b5a3f627dc2cfbde637ce9ebfc (diff)
downloadpyparsing-git-df9b2d50b75ee42663195058f3112e6c440381c5.tar.gz
Replace bare 'except:' with 'except Exception;'
Catching all exceptions is generally considered a bad practice under most circumstances as it will also catch KeyboardInterrupt and SystemExit. These special cases should be raised to the interpreter to allow the Python process to exit. This fix complies with pycodestyle's error code E722: https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes > do not use bare except, specify exception instead
-rw-r--r--examples/LAparser.py2
-rw-r--r--examples/dfmparse.py2
-rw-r--r--examples/pythonGrammarParser.py2
-rw-r--r--examples/verilogParse.py4
-rw-r--r--unitTests.py8
5 files changed, 9 insertions, 9 deletions
diff --git a/examples/LAparser.py b/examples/LAparser.py
index 3714975..41e8b4f 100644
--- a/examples/LAparser.py
+++ b/examples/LAparser.py
@@ -404,7 +404,7 @@ if __name__ == '__main__':
else:
try:
print(parse(input_string))
- except:
+ except Exception:
pass
# obtain new input string
diff --git a/examples/dfmparse.py b/examples/dfmparse.py
index d77a7ff..ae74bf0 100644
--- a/examples/dfmparse.py
+++ b/examples/dfmparse.py
@@ -161,7 +161,7 @@ def main(testfiles=None, action=printer):
try:
retval[f] = object_definition.parseFile(f)
success += 1
- except:
+ except Exception:
failures.append(f)
if failures:
diff --git a/examples/pythonGrammarParser.py b/examples/pythonGrammarParser.py
index aed6bbe..ed6a484 100644
--- a/examples/pythonGrammarParser.py
+++ b/examples/pythonGrammarParser.py
@@ -170,7 +170,7 @@ def makeGroupObject(cls):
def groupAction(s,l,t):
try:
return cls(t[0].asList())
- except:
+ except Exception:
return cls(t)
return groupAction
diff --git a/examples/verilogParse.py b/examples/verilogParse.py
index 9477e38..da97286 100644
--- a/examples/verilogParse.py
+++ b/examples/verilogParse.py
@@ -81,7 +81,7 @@ psycoOn = False
if usePackrat:
try:
ParserElement.enablePackrat()
- except:
+ except Exception:
pass
else:
packratOn = True
@@ -91,7 +91,7 @@ if usePsyco:
try:
import psyco
psyco.full()
- except:
+ except Exception:
print("failed to import psyco Python optimizer")
else:
psycoOn = True
diff --git a/unitTests.py b/unitTests.py
index 7dcc237..851a98a 100644
--- a/unitTests.py
+++ b/unitTests.py
@@ -850,7 +850,7 @@ class ParseKeywordTest(ParseTestCase):
print_("Match Literal", end=' ')
try:
print_(lit.parseString(s))
- except:
+ except Exception:
print_("failed")
if litShouldPass:
self.assertTrue(False, "Literal failed to match %s, should have" % s)
@@ -861,7 +861,7 @@ class ParseKeywordTest(ParseTestCase):
print_("Match Keyword", end=' ')
try:
print_(kw.parseString(s))
- except:
+ except Exception:
print_("failed")
if kwShouldPass:
self.assertTrue(False, "Keyword failed to match %s, should have" % s)
@@ -3939,10 +3939,10 @@ class MiscellaneousParserTests(ParseTestCase):
print_(t, repr(t))
try:
names.append( t[0].getName() )
- except:
+ except Exception:
try:
names.append( t.getName() )
- except:
+ except Exception:
names.append( None )
print_(teststring)
print_(names)