Skip to content

Commit 74577ee

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#21107: test: remove type: comments in favour of actual annotations
9913419 test: remove type: comments in favour of actual annotations (fanquake) Pull request description: 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. ACKs for top commit: MarcoFalke: review ACK 9913419 jnewbery: Code review ACK 9913419 Tree-SHA512: 63aba5eef6c1320578f66cf8a6d85ac9dbab9d30b0d21e6e966be8216e63606de12321320c2958c67933bf68d10f2e76e9c43928e5989614cea34dde4187aad8
1 parent 9a92452 commit 74577ee

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

test/functional/data/invalid_txs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BadTxTemplate:
4040
__metaclass__ = abc.ABCMeta
4141

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

4545
# Only specified if it differs from mempool acceptance error.
4646
block_reject_reason = ""

test/functional/p2p_message_capture.py

Lines changed: 3 additions & 3 deletions
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

test/functional/test_framework/script.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from .ripemd160 import ripemd160
2121

2222
MAX_SCRIPT_ELEMENT_SIZE = 520
23-
OPCODE_NAMES = {} # type: Dict[CScriptOp, str]
24-
2523
def hash160(s):
2624
return ripemd160(sha256(s))
2725

@@ -36,7 +34,6 @@ def bn2vch(v):
3634
# Serialize to bytes
3735
return encoded_v.to_bytes(n_bytes, 'little')
3836

39-
_opcode_instances = [] # type: List[CScriptOp]
4037
class CScriptOp(int):
4138
"""A single script opcode"""
4239
__slots__ = ()
@@ -100,6 +97,9 @@ def __new__(cls, n):
10097
_opcode_instances.append(super().__new__(cls, n))
10198
return _opcode_instances[n]
10299

100+
OPCODE_NAMES: Dict[CScriptOp, str] = {}
101+
_opcode_instances: List[CScriptOp] = []
102+
103103
# Populate opcode instance table
104104
for n in range(0xff + 1):
105105
CScriptOp(n)

0 commit comments

Comments
 (0)