Skip to content

Commit

Permalink
Merge pull request #1468 from graingert/fix-some-more-flake8-violations
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 26, 2020
2 parents da0bbc6 + 78c7452 commit 0542c9d
Show file tree
Hide file tree
Showing 133 changed files with 308 additions and 304 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: 2 additions & 0 deletions docs/core/examples/echoserv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Protocol Implementation

# This is just about the simplest possible protocol


class Echo(Protocol):
def dataReceived(self, data):
"""
Expand Down
2 changes: 2 additions & 0 deletions docs/core/examples/echoserv_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from twisted.internet import reactor

# Here's a UDP version of the simplest possible protocol


class EchoUDP(DatagramProtocol):
def datagramReceived(self, datagram, address):
self.transport.write(datagram, address)
Expand Down
2 changes: 2 additions & 0 deletions docs/core/examples/shaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
serverFilter.buckets[None] = serverBucket

# Web service is also limited per-host:


class WebClientBucket(htb.Bucket):
# Your first 10k is free
maxburst = 10000
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 @@ -3,6 +3,7 @@
from slides import *
from twslides import *


class PythonSource:
def __init__(self, content):
self.content = content
Expand Down
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
14 changes: 0 additions & 14 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ per-file-ignores =
E265,
# too many leading '#' for block comment
E266,
# expected 2 blank lines, found 1
E302,
# expected 1 blank line before a nested definition, found 0
E306,
# multiple imports on one line
E401,
# module level import not at top of file
Expand All @@ -142,12 +138,8 @@ per-file-ignores =
E711,
# comparison to True should be 'if cond is True:' or 'if cond:'
E712,
# test for membership should be 'not in'
E713,
# 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 @@ -156,21 +148,15 @@ per-file-ignores =
E743,
# .has_key() is deprecated, use 'in'
W601,
# invalid escape sequence '\)'
W605,
docs/*:
# block comment should start with '# '
E265,
# too many leading '#' for block comment
E266,
# expected 2 blank lines, found 1
E302,
# multiple imports on one line
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
3 changes: 2 additions & 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 Expand Up @@ -214,6 +214,7 @@ def quit(self):
"""
self._quit.set()
# In case all the workers are idle when we do this.

@self._coordinator.do
def startFinishing():
self._shouldQuitCoordinator = True
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
3 changes: 2 additions & 1 deletion src/twisted/conch/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def __init__(self, creator):
# and to signal to other parts of this implementation (in particular
# connectionLost) that it has already been fired and does not need to
# be fired again.

def readyFired(result):
self.connectionReady = None
return result
Expand Down Expand Up @@ -785,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
1 change: 1 addition & 0 deletions src/twisted/conch/test/test_filetransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ def buildServerConnection(self):
# make a server connection
conn = connection.SSHConnection()
# server connections have a 'self.transport.avatar'.

class DummyTransport:
def __init__(self):
self.transport = self
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
2 changes: 2 additions & 0 deletions src/twisted/cred/_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
}

# DigestCalcHA1


def calcHA1(
pszAlg, pszUserName, pszRealm, pszPassword, pszNonce, pszCNonce, preHA1=None
):
Expand Down

0 comments on commit 0542c9d

Please sign in to comment.