Skip to content

Commit

Permalink
Merge bitcoin#21107: test: remove type: comments in favour of actual …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
MarcoFalke authored and vijaydasmp committed Feb 7, 2024
1 parent 5323a78 commit 50a7fe4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/functional/data/invalid_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BadTxTemplate:
__metaclass__ = abc.ABCMeta

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

# Only specified if it differs from mempool acceptance error.
block_reject_reason = ""
Expand Down
6 changes: 3 additions & 3 deletions test/functional/p2p_message_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def mini_parser(dat_file):
if not tmp_header_raw:
break
tmp_header = BytesIO(tmp_header_raw)
int.from_bytes(tmp_header.read(TIME_SIZE), "little") # type: int
tmp_header.read(TIME_SIZE) # skip the timestamp field
raw_msgtype = tmp_header.read(MSGTYPE_SIZE)
msgtype = raw_msgtype.split(b'\x00', 1)[0] # type: bytes
msgtype: bytes = raw_msgtype.split(b'\x00', 1)[0] # type: bytes
remainder = raw_msgtype.split(b'\x00', 1)[1]
assert(len(msgtype) > 0)
assert(msgtype in MESSAGEMAP)
assert(len(remainder) == 0 or not remainder.decode().isprintable())
length = int.from_bytes(tmp_header.read(LENGTH_SIZE), "little") # type: int
length: int = int.from_bytes(tmp_header.read(LENGTH_SIZE), "little")
data = f_in.read(length)
assert_equal(len(data), length)

Expand Down
6 changes: 3 additions & 3 deletions test/functional/test_framework/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from .ripemd160 import ripemd160

MAX_SCRIPT_ELEMENT_SIZE = 520
OPCODE_NAMES = {} # type: Dict[CScriptOp, str]

def hash160(s):
return ripemd160(sha256(s))

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

_opcode_instances = [] # type: List[CScriptOp]
class CScriptOp(int):
"""A single script opcode"""
__slots__ = ()
Expand Down Expand Up @@ -100,6 +97,9 @@ def __new__(cls, n):
_opcode_instances.append(super().__new__(cls, n))
return _opcode_instances[n]

OPCODE_NAMES: Dict[CScriptOp, str] = {}
_opcode_instances: List[CScriptOp] = []

# Populate opcode instance table
for n in range(0xff + 1):
CScriptOp(n)
Expand Down

0 comments on commit 50a7fe4

Please sign in to comment.