BIP352: complete return type annotations in bitcoin_utils #2154

pull omipheo wants to merge 1 commits into bitcoin:master from omipheo:bip-0352-typing-return-annotations changing 1 files +8 −8
  1. omipheo commented at 6:10 AM on May 8, 2026: none

    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:

  2. BIP352: complete return type annotations in bitcoin_utils
    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.
    3b76c84d6f
  3. jonatack commented at 7:34 PM on May 8, 2026: member

    Approach ACK

Contributors

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-09 19:10 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me