BIP352: complete return type annotations in bitcoin_utils#2154
Open
omipheo wants to merge 1 commit intobitcoin:masterfrom
Open
BIP352: complete return type annotations in bitcoin_utils#2154omipheo wants to merge 1 commit intobitcoin:masterfrom
omipheo wants to merge 1 commit intobitcoin:masterfrom
Conversation
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.
Member
|
Approach ACK |
|
utACK 3b76c84 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The serialization helpers in
bip-0352/bitcoin_utils.pyare partiallytyped.
ser_uint32,hash160, and theis_p2*helpers already declareboth argument and return types, but the surrounding
from_hex,ser_uint256,deser_uint256,deser_txid,deser_compact_size,deser_string, anddeser_string_vectorhelpers 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
from_hexdef from_hex(hex_string)def from_hex(hex_string: str) -> BytesIOser_uint256def ser_uint256(u)def ser_uint256(u: int) -> bytesdeser_uint256def deser_uint256(f)def deser_uint256(f: BytesIO) -> intdeser_txiddef deser_txid(txid: str)def deser_txid(txid: str) -> bytesdeser_compact_sizedef deser_compact_size(f: BytesIO)def deser_compact_size(f: BytesIO) -> intdeser_stringdef deser_string(f: BytesIO)def deser_string(f: BytesIO) -> bytesdeser_string_vectordef deser_string_vector(f: BytesIO)def deser_string_vector(f: BytesIO) -> List[bytes]Listis added to the existingtypingimport. Theser_uint32andhash160annotations on adjacent lines were the model.Verification
Imported the module and round-tripped each helper to confirm the
runtime behavior is unchanged: