mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
Merge bitcoin/bitcoin#25867: lint: enable E722 do not use bare except
61bb4e783b
lint: enable E722 do not use bare except (Leonardo Lazzaro) Pull request description: Improve test code and enable E722 lint check. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException:). Reference: https://peps.python.org/pep-0008/#programming-recommendations ACKs for top commit: MarcoFalke: lgtm ACK61bb4e783b
Tree-SHA512: c7497769d5745fa02c78a20f4a0e555d8d3996d64af6faf1ce28e22ac1d8be415b98e967294679007b7bda2a9fd04031a9d140b24201e00257ceadeb5c5d7665
This commit is contained in:
commit
0c579203d2
10 changed files with 11 additions and 10 deletions
|
@ -34,7 +34,7 @@ def check_ELF_RELRO(binary) -> bool:
|
||||||
flags = binary.get(lief.ELF.DYNAMIC_TAGS.FLAGS)
|
flags = binary.get(lief.ELF.DYNAMIC_TAGS.FLAGS)
|
||||||
if flags.value & lief.ELF.DYNAMIC_FLAGS.BIND_NOW:
|
if flags.value & lief.ELF.DYNAMIC_FLAGS.BIND_NOW:
|
||||||
have_bindnow = True
|
have_bindnow = True
|
||||||
except:
|
except Exception:
|
||||||
have_bindnow = False
|
have_bindnow = False
|
||||||
|
|
||||||
return have_gnu_relro and have_bindnow
|
return have_gnu_relro and have_bindnow
|
||||||
|
|
|
@ -142,7 +142,7 @@ if args.captcha != '': # Retrieve a captcha
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = session.post(args.faucet, data=data)
|
res = session.post(args.faucet, data=data)
|
||||||
except:
|
except Exception:
|
||||||
raise SystemExit(f"Unexpected error when contacting faucet: {sys.exc_info()[0]}")
|
raise SystemExit(f"Unexpected error when contacting faucet: {sys.exc_info()[0]}")
|
||||||
|
|
||||||
# Display the output as per the returned status code
|
# Display the output as per the returned status code
|
||||||
|
|
|
@ -85,7 +85,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
|
||||||
self.nodes[node_index].waitforblock(expected_tip)
|
self.nodes[node_index].waitforblock(expected_tip)
|
||||||
utxo_hash = self.nodes[node_index].gettxoutsetinfo()['hash_serialized_2']
|
utxo_hash = self.nodes[node_index].gettxoutsetinfo()['hash_serialized_2']
|
||||||
return utxo_hash
|
return utxo_hash
|
||||||
except:
|
except Exception:
|
||||||
# An exception here should mean the node is about to crash.
|
# An exception here should mean the node is about to crash.
|
||||||
# If bitcoind exits, then try again. wait_for_node_exit()
|
# If bitcoind exits, then try again. wait_for_node_exit()
|
||||||
# should raise an exception if bitcoind doesn't exit.
|
# should raise an exception if bitcoind doesn't exit.
|
||||||
|
|
|
@ -85,7 +85,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||||
self.connect_nodes(0, 2)
|
self.connect_nodes(0, 2)
|
||||||
try:
|
try:
|
||||||
self.sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
|
self.sync_blocks([self.nodes[0], self.nodes[2]], timeout=5)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# node2 must remain at height 0
|
# node2 must remain at height 0
|
||||||
assert_equal(self.nodes[2].getblockheader(self.nodes[2].getbestblockhash())['height'], 0)
|
assert_equal(self.nodes[2].getblockheader(self.nodes[2].getbestblockhash())['height'], 0)
|
||||||
|
|
|
@ -16,7 +16,7 @@ def unidirectional_node_sync_via_rpc(node_src, node_dest):
|
||||||
try:
|
try:
|
||||||
assert len(node_dest.getblock(blockhash, False)) > 0
|
assert len(node_dest.getblock(blockhash, False)) > 0
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
blocks_to_copy.append(blockhash)
|
blocks_to_copy.append(blockhash)
|
||||||
blockhash = node_src.getblockheader(blockhash, True)['previousblockhash']
|
blockhash = node_src.getblockheader(blockhash, True)['previousblockhash']
|
||||||
blocks_to_copy.reverse()
|
blocks_to_copy.reverse()
|
||||||
|
|
|
@ -385,7 +385,7 @@ class P2PInterface(P2PConnection):
|
||||||
self.message_count[msgtype] += 1
|
self.message_count[msgtype] += 1
|
||||||
self.last_message[msgtype] = message
|
self.last_message[msgtype] = message
|
||||||
getattr(self, 'on_' + msgtype)(message)
|
getattr(self, 'on_' + msgtype)(message)
|
||||||
except:
|
except Exception:
|
||||||
print("ERROR delivering %s (%s)" % (repr(message), sys.exc_info()[0]))
|
print("ERROR delivering %s (%s)" % (repr(message), sys.exc_info()[0]))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
@ -557,7 +557,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||||
node.start(extra_args[i], *args, **kwargs)
|
node.start(extra_args[i], *args, **kwargs)
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
node.wait_for_rpc_connection()
|
node.wait_for_rpc_connection()
|
||||||
except:
|
except Exception:
|
||||||
# If one node failed to start, stop the others
|
# If one node failed to start, stop the others
|
||||||
self.stop_nodes()
|
self.stop_nodes()
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -829,7 +829,7 @@ class RPCOverloadWrapper():
|
||||||
int(address ,16)
|
int(address ,16)
|
||||||
is_hex = True
|
is_hex = True
|
||||||
desc = descsum_create('raw(' + address + ')')
|
desc = descsum_create('raw(' + address + ')')
|
||||||
except:
|
except Exception:
|
||||||
desc = descsum_create('addr(' + address + ')')
|
desc = descsum_create('addr(' + address + ')')
|
||||||
reqs = [{
|
reqs = [{
|
||||||
'desc': desc,
|
'desc': desc,
|
||||||
|
|
|
@ -47,6 +47,7 @@ ENABLED = (
|
||||||
'E711,' # comparison to None should be 'if cond is None:'
|
'E711,' # comparison to None should be 'if cond is None:'
|
||||||
'E714,' # test for object identity should be "is not"
|
'E714,' # test for object identity should be "is not"
|
||||||
'E721,' # do not compare types, use "isinstance()"
|
'E721,' # do not compare types, use "isinstance()"
|
||||||
|
'E722,' # do not use bare 'except'
|
||||||
'E742,' # do not define classes named "l", "O", or "I"
|
'E742,' # do not define classes named "l", "O", or "I"
|
||||||
'E743,' # do not define functions named "l", "O", or "I"
|
'E743,' # do not define functions named "l", "O", or "I"
|
||||||
'E901,' # SyntaxError: invalid syntax
|
'E901,' # SyntaxError: invalid syntax
|
||||||
|
|
|
@ -54,7 +54,7 @@ def bctester(testDir, input_basename, buildenv):
|
||||||
try:
|
try:
|
||||||
bctest(testDir, testObj, buildenv)
|
bctest(testDir, testObj, buildenv)
|
||||||
logging.info("PASSED: " + testObj["description"])
|
logging.info("PASSED: " + testObj["description"])
|
||||||
except:
|
except Exception:
|
||||||
logging.info("FAILED: " + testObj["description"])
|
logging.info("FAILED: " + testObj["description"])
|
||||||
failed_testcases.append(testObj["description"])
|
failed_testcases.append(testObj["description"])
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ def bctest(testDir, testObj, buildenv):
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(testDir, outputFn), encoding="utf8") as f:
|
with open(os.path.join(testDir, outputFn), encoding="utf8") as f:
|
||||||
outputData = f.read()
|
outputData = f.read()
|
||||||
except:
|
except Exception:
|
||||||
logging.error("Output file " + outputFn + " cannot be opened")
|
logging.error("Output file " + outputFn + " cannot be opened")
|
||||||
raise
|
raise
|
||||||
if not outputData:
|
if not outputData:
|
||||||
|
|
Loading…
Add table
Reference in a new issue