Skip to content

Commit f17aca6

Browse files
committed
Merge #14903: tests: Handle ImportError explicitly, improve comparisons against None
c9ba253 Add E711 to flake8 check (Daniel Ingram) 17b5520 Compare to None with is/is not (Daniel Ingram) 1b89074 Change '== None' to 'is None' (Daniel Ingram) 16d2937 Handle exception as ImportError (Daniel Ingram) Pull request description: Tree-SHA512: aa5875ea3d9ac47ac898545ff023b511042cd377ea0c4594074daae119f3d4f3fc295721aad94a732a907086ecb32bce19a8eed38adf479f12663c4e8944f721
2 parents 6d0a147 + c9ba253 commit f17aca6

File tree

9 files changed

+18
-17
lines changed

9 files changed

+18
-17
lines changed

contrib/devtools/clang-format-diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def main():
109109
match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line)
110110
if match:
111111
filename = match.group(2)
112-
if filename == None:
112+
if filename is None:
113113
continue
114114

115115
if args.regex is not None:

contrib/devtools/copyright_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def get_git_change_year_range(filename):
491491

492492
def file_already_has_core_copyright(file_lines):
493493
index, _ = get_updatable_copyright_line(file_lines)
494-
return index != None
494+
return index is not None
495495

496496
################################################################################
497497
# insert header execution

contrib/devtools/github-merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import codecs
2626
try:
2727
from urllib.request import Request,urlopen
28-
except:
28+
except ImportError:
2929
from urllib2 import Request,urlopen
3030

3131
# External tools (can be overridden using environment)

contrib/devtools/update-translations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def escape_cdata(text):
125125
return text
126126

127127
def contains_bitcoin_addr(text, errors):
128-
if text != None and ADDRESS_REGEXP.search(text) != None:
128+
if text is not None and ADDRESS_REGEXP.search(text) is not None:
129129
errors.append('Translation "%s" contains a bitcoin address. This will be removed.' % (text))
130130
return True
131131
return False

test/functional/interface_http.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def run_test(self):
3131
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
3232
out1 = conn.getresponse().read()
3333
assert(b'"error":null' in out1)
34-
assert(conn.sock!=None) #according to http/1.1 connection must still be open!
34+
assert(conn.sock is not None) #according to http/1.1 connection must still be open!
3535

3636
#send 2nd request without closing connection
3737
conn.request('POST', '/', '{"method": "getchaintips"}', headers)
3838
out1 = conn.getresponse().read()
3939
assert(b'"error":null' in out1) #must also response with a correct json-rpc message
40-
assert(conn.sock!=None) #according to http/1.1 connection must still be open!
40+
assert(conn.sock is not None) #according to http/1.1 connection must still be open!
4141
conn.close()
4242

4343
#same should be if we add keep-alive because this should be the std. behaviour
@@ -48,13 +48,13 @@ def run_test(self):
4848
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
4949
out1 = conn.getresponse().read()
5050
assert(b'"error":null' in out1)
51-
assert(conn.sock!=None) #according to http/1.1 connection must still be open!
51+
assert(conn.sock is not None) #according to http/1.1 connection must still be open!
5252

5353
#send 2nd request without closing connection
5454
conn.request('POST', '/', '{"method": "getchaintips"}', headers)
5555
out1 = conn.getresponse().read()
5656
assert(b'"error":null' in out1) #must also response with a correct json-rpc message
57-
assert(conn.sock!=None) #according to http/1.1 connection must still be open!
57+
assert(conn.sock is not None) #according to http/1.1 connection must still be open!
5858
conn.close()
5959

6060
#now do the same with "Connection: close"
@@ -65,7 +65,7 @@ def run_test(self):
6565
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
6666
out1 = conn.getresponse().read()
6767
assert(b'"error":null' in out1)
68-
assert(conn.sock==None) #now the connection must be closed after the response
68+
assert(conn.sock is None) #now the connection must be closed after the response
6969

7070
#node1 (2nd node) is running with disabled keep-alive option
7171
urlNode1 = urllib.parse.urlparse(self.nodes[1].url)
@@ -88,7 +88,7 @@ def run_test(self):
8888
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
8989
out1 = conn.getresponse().read()
9090
assert(b'"error":null' in out1)
91-
assert(conn.sock!=None) #connection must be closed because bitcoind should use keep-alive by default
91+
assert(conn.sock is not None) #connection must be closed because bitcoind should use keep-alive by default
9292

9393
# Check excessive request size
9494
conn = http.client.HTTPConnection(urlNode2.hostname, urlNode2.port)

test/functional/mining_prioritisetransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run_test(self):
8484
high_fee_tx = x
8585

8686
# Something high-fee should have been mined!
87-
assert(high_fee_tx != None)
87+
assert(high_fee_tx is not None)
8888

8989
# Add a prioritisation before a tx is in the mempool (de-prioritising a
9090
# high-fee transaction so that it's now low fee).

test/functional/test_framework/messages.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def __init__(self, p2pheaders_and_shortids = None):
764764
self.prefilled_txn = []
765765
self.use_witness = False
766766

767-
if p2pheaders_and_shortids != None:
767+
if p2pheaders_and_shortids is not None:
768768
self.header = p2pheaders_and_shortids.header
769769
self.nonce = p2pheaders_and_shortids.nonce
770770
self.shortids = p2pheaders_and_shortids.shortids
@@ -822,7 +822,7 @@ class BlockTransactionsRequest:
822822

823823
def __init__(self, blockhash=0, indexes = None):
824824
self.blockhash = blockhash
825-
self.indexes = indexes if indexes != None else []
825+
self.indexes = indexes if indexes is not None else []
826826

827827
def deserialize(self, f):
828828
self.blockhash = deser_uint256(f)
@@ -863,7 +863,7 @@ class BlockTransactions:
863863

864864
def __init__(self, blockhash=0, transactions = None):
865865
self.blockhash = blockhash
866-
self.transactions = transactions if transactions != None else []
866+
self.transactions = transactions if transactions is not None else []
867867

868868
def deserialize(self, f):
869869
self.blockhash = deser_uint256(f)
@@ -1052,7 +1052,7 @@ class msg_getdata:
10521052
command = b"getdata"
10531053

10541054
def __init__(self, inv=None):
1055-
self.inv = inv if inv != None else []
1055+
self.inv = inv if inv is not None else []
10561056

10571057
def deserialize(self, f):
10581058
self.inv = deser_vector(f, CInv)

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(self, i, datadir, *, rpchost, timewait, bitcoind, bitcoin_cli, mock
6868
self.rpc_timeout = timewait
6969
self.binary = bitcoind
7070
self.coverage_dir = coverage_dir
71-
if extra_conf != None:
71+
if extra_conf is not None:
7272
append_config(datadir, extra_conf)
7373
# Most callers will just need to add extra args to the standard list below.
7474
# For those callers that need more flexibility, they can just set the args property directly.

test/lint/lint-python.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export LC_ALL=C
3636
# E701 multiple statements on one line (colon)
3737
# E702 multiple statements on one line (semicolon)
3838
# E703 statement ends with a semicolon
39+
# E711 comparison to None should be 'if cond is None:'
3940
# E714 test for object identity should be "is not"
4041
# E721 do not compare types, use "isinstance()"
4142
# E741 do not use variables named "l", "O", or "I"
@@ -87,4 +88,4 @@ elif PYTHONWARNINGS="ignore" flake8 --version | grep -q "Python 2"; then
8788
exit 0
8889
fi
8990

90-
PYTHONWARNINGS="ignore" flake8 --ignore=B,C,E,F,I,N,W --select=E101,E112,E113,E115,E116,E125,E129,E131,E133,E223,E224,E242,E266,E271,E272,E273,E274,E275,E304,E306,E401,E402,E502,E701,E702,E703,E714,E721,E741,E742,E743,E901,E902,F401,F402,F403,F404,F405,F406,F407,F601,F602,F621,F622,F631,F701,F702,F703,F704,F705,F706,F707,F811,F812,F821,F822,F823,F831,F841,W191,W291,W292,W293,W504,W601,W602,W603,W604,W605,W606 "${@:-.}"
91+
PYTHONWARNINGS="ignore" flake8 --ignore=B,C,E,F,I,N,W --select=E101,E112,E113,E115,E116,E125,E129,E131,E133,E223,E224,E242,E266,E271,E272,E273,E274,E275,E304,E306,E401,E402,E502,E701,E702,E703,E711,E714,E721,E741,E742,E743,E901,E902,F401,F402,F403,F404,F405,F406,F407,F601,F602,F621,F622,F631,F701,F702,F703,F704,F705,F706,F707,F811,F812,F821,F822,F823,F831,F841,W191,W291,W292,W293,W504,W601,W602,W603,W604,W605,W606 "${@:-.}"

0 commit comments

Comments
 (0)