Skip to content

Commit 9913419

Browse files
committed
test: remove type: comments in favour of actual annotations
Now that we require Python 3.6+, we should be using variable type annotations directly rather than # type: comments. Also takes care of the discarded value issue in p2p_message_capture.py. See: https://github.com/bitcoin/bitcoin/pull/19509/files#r571674446.
1 parent cf26ca3 commit 9913419

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: test/functional/data/invalid_txs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class BadTxTemplate:
5757
__metaclass__ = abc.ABCMeta
5858

5959
# The expected error code given by bitcoind upon submission of the tx.
60-
reject_reason = "" # type: Optional[str]
60+
reject_reason: Optional[str] = ""
6161

6262
# Only specified if it differs from mempool acceptance error.
6363
block_reject_reason = ""

Diff for: test/functional/p2p_message_capture.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ def mini_parser(dat_file):
4242
if not tmp_header_raw:
4343
break
4444
tmp_header = BytesIO(tmp_header_raw)
45-
int.from_bytes(tmp_header.read(TIME_SIZE), "little") # type: int
45+
tmp_header.read(TIME_SIZE) # skip the timestamp field
4646
raw_msgtype = tmp_header.read(MSGTYPE_SIZE)
47-
msgtype = raw_msgtype.split(b'\x00', 1)[0] # type: bytes
47+
msgtype: bytes = raw_msgtype.split(b'\x00', 1)[0]
4848
remainder = raw_msgtype.split(b'\x00', 1)[1]
4949
assert(len(msgtype) > 0)
5050
assert(msgtype in MESSAGEMAP)
5151
assert(len(remainder) == 0 or not remainder.decode().isprintable())
52-
length = int.from_bytes(tmp_header.read(LENGTH_SIZE), "little") # type: int
52+
length: int = int.from_bytes(tmp_header.read(LENGTH_SIZE), "little")
5353
data = f_in.read(length)
5454
assert_equal(len(data), length)
5555

Diff for: test/functional/test_framework/script.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
LOCKTIME_THRESHOLD = 500000000
3030
ANNEX_TAG = 0x50
3131

32-
OPCODE_NAMES = {} # type: Dict[CScriptOp, str]
33-
3432
LEAF_VERSION_TAPSCRIPT = 0xc0
3533

3634
def hash160(s):
@@ -47,7 +45,6 @@ def bn2vch(v):
4745
# Serialize to bytes
4846
return encoded_v.to_bytes(n_bytes, 'little')
4947

50-
_opcode_instances = [] # type: List[CScriptOp]
5148
class CScriptOp(int):
5249
"""A single script opcode"""
5350
__slots__ = ()
@@ -111,6 +108,9 @@ def __new__(cls, n):
111108
_opcode_instances.append(super().__new__(cls, n))
112109
return _opcode_instances[n]
113110

111+
OPCODE_NAMES: Dict[CScriptOp, str] = {}
112+
_opcode_instances: List[CScriptOp] = []
113+
114114
# Populate opcode instance table
115115
for n in range(0xff + 1):
116116
CScriptOp(n)

0 commit comments

Comments
 (0)