BIP352: complete type annotations on bitcoin_utils class methods#2160
Open
omipheo wants to merge 1 commit into
Open
BIP352: complete type annotations on bitcoin_utils class methods#2160omipheo wants to merge 1 commit into
omipheo wants to merge 1 commit into
Conversation
Direct follow-up to PR bitcoin#2154 (which annotated the free-function half of bip-0352/bitcoin_utils.py) and 2f7117c ("BIP352: fix Any typing"). The four classes in this file — COutPoint, VinInfo, CScriptWitness, and CTxInWitness — still had unannotated `__init__`, `serialize`, `deserialize`, and `is_null` methods. mypy could not flow types through the surrounding reference.py code that constructs and passes these objects. Annotate every method on all four classes: - COutPoint: __init__ (hash, n), serialize -> bytes, deserialize -> None - VinInfo: __init__ (typed Optional defaults for the three construct-on-None fields) - CScriptWitness: __init__ -> None, is_null -> bool, plus an inline stack: List[bytes] declaration matching what the rest of the file already assumes - CTxInWitness: __init__ -> None, deserialize -> "CTxInWitness" (forward ref since it returns self), is_null -> bool Adds Optional to the existing typing import (List was already added by bitcoin#2154). No behavior changes. Verified: mypy --ignore-missing-imports ./bip-0352/bitcoin_utils.py reports "Success: no issues found in 1 source file"; round-trip smoke tests on COutPoint serialize/deserialize, CScriptWitness is_null with empty + non-empty stack, CTxInWitness deserialize returning self, and VinInfo default-construction all match the pre-change behavior.
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
Direct follow-up to PR #2154 (which annotated the free-function half of
bip-0352/bitcoin_utils.py) and 2f7117c ("BIP352: fix Any typing"). The four classes in this file —COutPoint,VinInfo,CScriptWitness, andCTxInWitness— still had unannotated__init__,serialize,deserialize, andis_nullmethods, so mypy could not flow types through the surroundingreference.pycode that constructs and passes these objects.
This PR annotates every method on all four classes:
COutPoint__init__(hash: bytes, n: int) -> None,serialize() -> bytes,deserialize(f: BytesIO) -> NoneVinInfo__init__(typedOptionaldefaults for the three construct-on-Nonefields)CScriptWitness__init__() -> None,is_null() -> bool, plus an inlinestack: List[bytes]declaration matching what the rest of the file already assumesCTxInWitness__init__() -> None,deserialize(f: BytesIO) -> "CTxInWitness"(forward ref since it returnsself),is_null() -> boolOptionalis added to the existingtypingimport;Listwas already added by #2154. No behavior changes.Verification
Notes
bip-0352/bitcoin_utils.py, +18 / −11.