Summary
The serialization helpers in bip-0352/bitcoin_utils.py are partially
typed. ser_uint32, hash160, and the is_p2* helpers already declare
both argument and return types, but the surrounding from_hex,
ser_uint256, deser_uint256, deser_txid, deser_compact_size,
deser_string, and deser_string_vector helpers omit them.
Fill in the missing return types (and the obvious argument types) so
the file is consistent and so static analysis can flow types through
the callers in reference.py. Follow-up to 2f7117c
("BIP352: fix Any typing").
No behavior changes.
Diff
| Function | Before | After |
|---|---|---|
from_hex |
def from_hex(hex_string) |
def from_hex(hex_string: str) -> BytesIO |
ser_uint256 |
def ser_uint256(u) |
def ser_uint256(u: int) -> bytes |
deser_uint256 |
def deser_uint256(f) |
def deser_uint256(f: BytesIO) -> int |
deser_txid |
def deser_txid(txid: str) |
def deser_txid(txid: str) -> bytes |
deser_compact_size |
def deser_compact_size(f: BytesIO) |
def deser_compact_size(f: BytesIO) -> int |
deser_string |
def deser_string(f: BytesIO) |
def deser_string(f: BytesIO) -> bytes |
deser_string_vector |
def deser_string_vector(f: BytesIO) |
def deser_string_vector(f: BytesIO) -> List[bytes] |
List is added to the existing typing import. The ser_uint32 and
hash160 annotations on adjacent lines were the model.
Verification
Imported the module and round-tripped each helper to confirm the runtime behavior is unchanged: