Skip to content

Commit

Permalink
fix flake8 E722 do not use bare 'except'
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 26, 2020
1 parent a8fa466 commit 268354f
Show file tree
Hide file tree
Showing 120 changed files with 284 additions and 288 deletions.
2 changes: 1 addition & 1 deletion docs/core/benchmarks/deferreds.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def instantiateShootErrback():
d = defer.Deferred()
try:
1 / 0
except:
except BaseException:
d.errback()
d.addErrback(lambda x: None)

Expand Down
6 changes: 3 additions & 3 deletions docs/core/benchmarks/failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def fail(n):
for i in R:
try:
eval("deepFailure%d_0" % n)()
except:
except BaseException:
failure.Failure()


def fail_str(n):
for i in R:
try:
eval("deepFailure%d_0" % n)()
except:
except BaseException:
str(failure.Failure())


Expand All @@ -67,7 +67,7 @@ def fail_easy(n):
for i in R:
try:
failure.Failure(PythonException())
except:
except BaseException:
pass


Expand Down
2 changes: 1 addition & 1 deletion docs/core/examples/courier.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def filterMessage(self):
with open(self.messageFilename) as f:
emailParser.parse(f)
self.sendLine(b"200 Ok")
except:
except BaseException:
trace_dump()
self.sendLine(b"435 " + FILTERNAME.encode("ascii") + b" processing error")

Expand Down
2 changes: 1 addition & 1 deletion docs/core/examples/cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def lineReceived(self, line):
f(*line.split()[1:])
except TypeError:
self.sendLine(b"Wrong number of arguments.")
except:
except BaseException:
self.sendLine(b"Server error (probably your fault)")

def cmd_ANON(self):
Expand Down
2 changes: 1 addition & 1 deletion docs/core/examples/testlogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test(i):
warnings.warn("warning {}".format(i))
try:
raise RuntimeError("error {}".format(i))
except:
except BaseException:
log.err()


Expand Down
2 changes: 1 addition & 1 deletion docs/core/howto/listings/pb/trap_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def worksLike(obj):
print(" InsecureJelly: you tried to send something unsafe to them")
except (MyException, MyOtherException):
print(" remote raised a MyException") # or MyOtherException
except:
except BaseException:
print(" something else happened")
else:
print(" method successful, response:", response)
Expand Down
2 changes: 1 addition & 1 deletion docs/core/howto/logger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Capturing Failures
try:
1 / 0
except:
except BaseException:
log.failure("Math is hard!")
The emitted event will have the ``"log_failure"`` key set, which is a :api:`twisted.python.failure.Failure <Failure>` that captures the exception.
Expand Down
2 changes: 1 addition & 1 deletion docs/core/howto/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ functions:
try:
x = 1 / 0
except:
except BaseException:
log.err() # will log the ZeroDivisionError
:api:`twisted.python.log.startLogging <startLogging>`
Expand Down
2 changes: 1 addition & 1 deletion docs/core/howto/tutorial/listings/finger/fingerproxy.tac
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ProxyFingerService(service.Service):
def getUser(self, user):
try:
user, host = user.split("@", 1)
except:
except BaseException:
user = user.strip()
host = "127.0.0.1"
ret = finger(user, host)
Expand Down
2 changes: 1 addition & 1 deletion docs/historic/2003/europython/doanddont.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2>Exceptions -- Catching Too Much -- Example</h2>
<pre class="python">
try:
f = opne("file")
except:
except BaseException:
sys.exit("no such file")
</pre>

Expand Down
2 changes: 1 addition & 1 deletion docs/historic/2003/pycon/deferex/deferex-complex-raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class MyExc(Exception):
print(x)
except MyExc as me:
print("error (", me, "). x was:", x)
except:
except BaseException:
print("fatal error! abort!")
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def stopFactory(self):
try:
doSomethingElse()
except:
except BaseException:
log.deferr()
"""

Expand Down
2 changes: 1 addition & 1 deletion docs/words/examples/cursesclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def doRead(self):
# for testing too
try:
self.irc.sendLine(self.searchText)
except:
except BaseException:
pass
self.stdscr.refresh()
self.searchText = ""
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ per-file-ignores =
E712,
# do not compare types, use 'isinstance()'
E721,
# do not use bare 'except'
E722,
# do not assign a lambda expression, use a def
E731,
# ambiguous variable name 'l'
Expand All @@ -159,8 +157,6 @@ per-file-ignores =
E401,
# module level import not at top of file
E402,
# do not use bare 'except'
E722,
# ambiguous variable name 'l'
E741,
# 'string' imported but unused
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/_threads/_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _coordinateThisTask(self, task):
def doWork():
try:
task()
except:
except BaseException:
self._logException()

@self._coordinator.do
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def runReactorWithLogging(config, oldstdout, oldstderr, profiler=None, reactor=N
pdb.runcall(reactor.run)
else:
reactor.run()
except:
except BaseException:
close = False
if config["nodaemon"]:
file = oldstdout
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/client/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def isInKnownHosts(host, pubKey, options):
continue
try:
decodedKey = decodebytes(encodedKey)
except:
except BaseException:
continue
if decodedKey == pubKey:
return 1
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def _opener(self):
"""
try:
return self.tty.open("rb+")
except:
except BaseException:
# Give back a file-like object from which can be read a byte string
# that KnownHostsFile recognizes as rejecting some option (b"no").
return _ReadFile(b"no")
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/conch/scripts/cftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def handleError():
exitStatus = 2
try:
reactor.stop()
except:
except BaseException:
pass
log.err(failure.Failure())
raise
Expand Down Expand Up @@ -517,7 +517,7 @@ def _cbPutMultipleNext(self, previousResult, files, remotePath, single=False):
try:
currentFile = files.pop(0)
localStream = open(currentFile, "rb")
except:
except BaseException:
self._printFailure(failure.Failure())
currentFile = None

Expand Down
8 changes: 4 additions & 4 deletions src/twisted/conch/scripts/conch.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ def run():
fd = sys.stdin.fileno()
try:
old = tty.tcgetattr(fd)
except:
except BaseException:
old = None
try:
oldUSR1 = signal.signal(
signal.SIGUSR1, lambda *a: reactor.callLater(0, reConnect)
)
except:
except BaseException:
oldUSR1 = None
try:
reactor.run()
Expand Down Expand Up @@ -196,7 +196,7 @@ def handleError():
def _stopReactor():
try:
reactor.stop()
except:
except BaseException:
pass


Expand Down Expand Up @@ -537,7 +537,7 @@ def _enterRawMode():
try:
old = tty.tcgetattr(fd)
new = old[:]
except:
except BaseException:
log.msg("not a typewriter!")
else:
# iflage
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/scripts/tkconch.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def getPublicKey(self):
return
try:
return keys.Key.fromFile(file).blob()
except:
except BaseException:
return self.getPublicKey() # try again

def getPrivateKey(self):
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_cftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def tearDown(self):
for f in ["dsa_test.pub", "dsa_test", "kh_test"]:
try:
os.remove(f)
except:
except BaseException:
pass
return SFTPTestBase.tearDown(self)

Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_conch.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def assertExecuteWithKexAlgorithm(self, keyExchangeAlgo):
if not isinstance(output, str):
output = output.decode("utf-8")
kexAlgorithms = output.split()
except:
except BaseException:
pass

if keyExchangeAlgo not in kexAlgorithms:
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def connect(self, factory):

try:
protocol = factory.buildProtocol(MemoryAddress())
except:
except BaseException:
return fail()
else:
self.pump = connect(
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_manhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def determineDefaultFunctionName():
"""
try:
1 // 0
except:
except BaseException:
# The last frame is this function. The second to last frame is this
# function's caller, which is module-scope, which is what we want,
# so -2.
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/test/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def global_tcpip_forward(self, data):
),
interface=host,
)
except:
except BaseException:
log.err(None, "something went wrong with remote->local forwarding")
return 0
else:
Expand Down
2 changes: 1 addition & 1 deletion src/twisted/conch/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def global_tcpip_forward(self, data):
),
interface=hostToBind,
)
except:
except BaseException:
return 0
else:
self.listeners[(hostToBind, portToBind)] = listener
Expand Down
14 changes: 7 additions & 7 deletions src/twisted/enterprise/adbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def rollback(self):
curs.close()
self._connection.commit()
return
except:
except BaseException:
log.err(None, "Rollback failed")

self._pool.disconnect(self._connection)
Expand Down Expand Up @@ -104,7 +104,7 @@ def reopen(self):
try:
self._cursor = self._connection.cursor()
return
except:
except BaseException:
if not self._pool.reconnect:
raise
else:
Expand Down Expand Up @@ -284,11 +284,11 @@ def _runWithConnection(self, func, *args, **kw):
result = func(conn, *args, **kw)
conn.commit()
return result
except:
except BaseException:
excType, excValue, excTraceback = sys.exc_info()
try:
conn.rollback()
except:
except BaseException:
log.err(None, "Rollback failed")
compat.reraise(excValue, excTraceback)

Expand Down Expand Up @@ -436,7 +436,7 @@ def _close(self, conn):
log.msg("adbapi closing: {}".format(self.dbapiName))
try:
conn.close()
except:
except BaseException:
log.err(None, "Connection close failed")

def _runInteraction(self, interaction, *args, **kw):
Expand All @@ -447,11 +447,11 @@ def _runInteraction(self, interaction, *args, **kw):
trans.close()
conn.commit()
return result
except:
except BaseException:
excType, excValue, excTraceback = sys.exc_info()
try:
conn.rollback()
except:
except BaseException:
log.err(None, "Rollback failed")
compat.reraise(excValue, excTraceback)

Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/_posixstdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _writeConnectionLost(self, reason):
if p:
try:
p.writeConnectionLost()
except:
except BaseException:
log.err()
self.connectionLost(failure.Failure())

Expand All @@ -133,7 +133,7 @@ def _readConnectionLost(self, reason):
if p:
try:
p.readConnectionLost()
except:
except BaseException:
log.err()
self.connectionLost(failure.Failure())
else:
Expand Down
4 changes: 2 additions & 2 deletions src/twisted/internet/_producer_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _pull(self):
while True:
try:
self._producer.resumeProducing()
except:
except BaseException:
log.err(
None,
"%s failed, producing will be stopped:"
Expand All @@ -72,7 +72,7 @@ def _pull(self):
self._consumer.unregisterProducer()
# The consumer should now call stopStreaming() on us,
# thus stopping the streaming.
except:
except BaseException:
# Since the consumer blew up, we may not have had
# stopStreaming() called, so we just stop on our own:
log.err(
Expand Down
Loading

0 comments on commit 268354f

Please sign in to comment.