Skip to content

BIP352: complete return type annotations in bitcoin_utils#2154

Open
omipheo wants to merge 1 commit intobitcoin:masterfrom
omipheo:bip-0352-typing-return-annotations
Open

BIP352: complete return type annotations in bitcoin_utils#2154
omipheo wants to merge 1 commit intobitcoin:masterfrom
omipheo:bip-0352-typing-return-annotations

Conversation

@omipheo
Copy link
Copy Markdown

@omipheo omipheo commented May 8, 2026

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:

The serialization helpers in bip-0352/bitcoin_utils.py were partially
typed: ser_uint32, hash160, is_p2tr, is_p2wpkh, is_p2sh and is_p2pkh
already declare argument and return types, but the surrounding
from_hex / ser_uint256 / deser_uint256 / deser_txid / deser_compact_size
/ deser_string / deser_string_vector helpers omit them.

Annotate the missing return types (and fill in the obvious argument
types) so the file is consistent and so static analysis can flow types
through callers in reference.py. No behavior changes.
@jonatack
Copy link
Copy Markdown
Member

jonatack commented May 8, 2026

Approach ACK

@edilmedeiros
Copy link
Copy Markdown

utACK 3b76c84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants