diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py --- a/contrib/linearize/linearize-data.py +++ b/contrib/linearize/linearize-data.py @@ -156,7 +156,8 @@ (blkDate, blkTS) = get_blk_dt(blk_hdr) if self.timestampSplit and (blkDate > self.lastDate): - print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str) + print("New month " + blkDate.strftime("%Y-%m") + + " @ " + self.hash_str) self.lastDate = blkDate if self.outF: self.outF.close() diff --git a/test/functional/p2p_invalid_locator.py b/test/functional/p2p_invalid_locator.py --- a/test/functional/p2p_invalid_locator.py +++ b/test/functional/p2p_invalid_locator.py @@ -46,7 +46,7 @@ msg.locator.vHave = [int(node.getblockhash( i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)] node.p2p.send_message(msg) - if type(msg) == msg_getheaders: + if isinstance(msg, msg_getheaders): node.p2p.wait_for_header(int(node.getbestblockhash(), 16)) else: node.p2p.wait_for_block(int(node.getbestblockhash(), 16)) diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py --- a/test/functional/test_framework/address.py +++ b/test/functional/test_framework/address.py @@ -51,16 +51,16 @@ def check_key(key): - if (type(key) is str): + if (isinstance(key, str)): key = hex_str_to_bytes(key) # Assuming this is hex string - if (type(key) is bytes and (len(key) == 33 or len(key) == 65)): + if (isinstance(key, bytes) and (len(key) == 33 or len(key) == 65)): return key assert False def check_script(script): - if (type(script) is str): + if (isinstance(script, str)): script = hex_str_to_bytes(script) # Assuming this is hex string - if (type(script) is bytes or type(script) is CScript): + if (isinstance(script, bytes) or isinstance(script, CScript)): return script assert False diff --git a/test/functional/wallet_groups.py b/test/functional/wallet_groups.py --- a/test/functional/wallet_groups.py +++ b/test/functional/wallet_groups.py @@ -56,8 +56,7 @@ assert_equal(1, len(tx1["vin"])) assert_equal(2, len(tx1["vout"])) # one output should be 0.2, the other should be ~0.3 - v = [vout["value"] for vout in tx1["vout"]] - v.sort() + v = sorted([vout["value"] for vout in tx1["vout"]]) assert_approx(v[0], 0.2) assert_approx(v[1], 0.3, 0.0001) @@ -67,8 +66,7 @@ assert_equal(2, len(tx2["vin"])) assert_equal(2, len(tx2["vout"])) # one output should be 0.2, the other should be ~1.3 - v = [vout["value"] for vout in tx2["vout"]] - v.sort() + v = sorted([vout["value"] for vout in tx2["vout"]]) assert_approx(v[0], 0.2) assert_approx(v[1], 1.3, 0.0001) diff --git a/test/lint/lint-format-strings.py b/test/lint/lint-format-strings.py --- a/test/lint/lint-format-strings.py +++ b/test/lint/lint-format-strings.py @@ -59,8 +59,8 @@ >>> len(parse_function_calls("foo", "#define FOO foo();")) 0 """ - assert type(function_name) is str and type( - source_code) is str and function_name + assert isinstance(function_name, str) and isinstance( + source_code, str) and function_name lines = [re.sub("// .*", " ", line).strip() for line in source_code.split("\n") if not line.strip().startswith("#")] @@ -74,7 +74,7 @@ >>> normalize(" /* nothing */ foo\tfoo /* bar */ foo ") 'foo foo foo' """ - assert type(s) is str + assert isinstance(s, str) s = s.replace("\n", " ") s = s.replace("\t", " ") s = re.sub(r"/\*.*?\*/", " ", s) @@ -98,7 +98,7 @@ >>> escape(r'foo \\t foo \\n foo \\\\ foo \\ foo \\"bar\\"') 'foo [escaped-tab] foo [escaped-newline] foo \\\\\\\\ foo \\\\ foo [escaped-quote]bar[escaped-quote]' """ - assert type(s) is str + assert isinstance(s, str) for raw_value, escaped_value in ESCAPE_MAP.items(): s = s.replace(raw_value, escaped_value) return s @@ -113,7 +113,7 @@ >>> unescape("foo [escaped-tab] foo [escaped-newline] foo \\\\\\\\ foo \\\\ foo [escaped-quote]bar[escaped-quote]") 'foo \\\\t foo \\\\n foo \\\\\\\\ foo \\\\ foo \\\\"bar\\\\"' """ - assert type(s) is str + assert isinstance(s, str) for raw_value, escaped_value in ESCAPE_MAP.items(): s = s.replace(escaped_value, raw_value) return s @@ -146,8 +146,8 @@ >>> parse_function_call_and_arguments("foo", 'foo("foo")') ['foo(', '"foo"', ')'] """ - assert type(function_name) is str and type( - function_call) is str and function_name + assert isinstance(function_name, str) and isinstance( + function_call, str) and function_name remaining = normalize(escape(function_call)) expected_function_call = "{}(".format(function_name) assert remaining.startswith(expected_function_call) @@ -199,7 +199,7 @@ >>> parse_string_content('1 2 3') '' """ - assert type(argument) is str + assert isinstance(argument, str) string_content = "" in_string = False for char in normalize(escape(argument)): @@ -226,7 +226,7 @@ >>> count_format_specifiers("foo %d bar %i foo %% foo %*d foo") 4 """ - assert type(format_string) is str + assert isinstance(format_string, str) n = 0 in_specifier = False for i, char in enumerate(format_string):