diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1dbd36ad..31daf306 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -40,7 +40,7 @@ repos: args: [--notice=COPYRIGHT] files: python - repo: https://github.com/PyCQA/autoflake - rev: v2.2.0 + rev: v2.3.1 hooks: - id: autoflake args: @@ -54,7 +54,7 @@ repos: language: python types: [python] - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 + rev: v3.20.0 hooks: - id: pyupgrade args: [--py38-plus] @@ -62,7 +62,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 6.1.0 hooks: - id: isort name: isort (black profile, in place fixes) @@ -70,7 +70,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/docformatter - rev: v1.7.5 + rev: v1.7.7 hooks: - id: docformatter description: "Formats docstrings to follow PEP 257." @@ -78,7 +78,7 @@ repos: types: [python] args: ["--in-place"] - repo: https://github.com/DanielNoord/pydocstringformatter - rev: v0.7.3 + rev: v0.7.5 hooks: - id: pydocstringformatter language: python @@ -97,13 +97,13 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.3.0 hooks: - id: flake8 language: python types: [python] - - repo: https://github.com/psf/black - rev: 23.7.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 25.9.0 hooks: - id: black name: black (in place fixes) @@ -116,7 +116,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + rev: 1.8.6 hooks: - id: bandit name: bandit (btclib) @@ -125,7 +125,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 + rev: 1.8.6 hooks: - id: bandit name: bandit (tests) @@ -138,7 +138,7 @@ repos: language: python types: [python] - repo: https://github.com/PyCQA/pylint - rev: v3.0.0a6 + rev: v3.3.9 hooks: - id: pylint args: [ @@ -147,13 +147,13 @@ repos: language: python types: [python] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.18.2 hooks: - id: mypy language: python types: [python] - repo: https://github.com/mgedmin/check-manifest - rev: "0.49" + rev: "0.50" hooks: - id: check-manifest description: Check the completeness of MANIFEST.in for Python packages. @@ -161,6 +161,6 @@ repos: pass_filenames: false always_run: true - repo: https://github.com/regebro/pyroma - rev: "4.2" + rev: "5.0" hooks: - id: pyroma diff --git a/btclib/bip32/key_origin.py b/btclib/bip32/key_origin.py index 24f65158..e23743db 100644 --- a/btclib/bip32/key_origin.py +++ b/btclib/bip32/key_origin.py @@ -138,7 +138,7 @@ def decode_hd_key_paths(map_: Mapping[Octets, BIP32KeyOrigin] | None) -> HdKeyPa def encode_to_bip32_derivs( - hd_key_paths: Mapping[bytes, BIP32KeyOrigin] + hd_key_paths: Mapping[bytes, BIP32KeyOrigin], ) -> list[_BIP32Deriv]: """Return the json representation of the dataclass element.""" return [ @@ -152,7 +152,7 @@ def encode_to_bip32_derivs( def _decode_from_bip32_deriv( - bip32_deriv: Mapping[str, str] + bip32_deriv: Mapping[str, str], ) -> tuple[bytes, BIP32KeyOrigin]: # FIXME remove size checks to allow # the instantiation of invalid master_fingerprint and pub_key diff --git a/btclib/psbt/psbt_in.py b/btclib/psbt/psbt_in.py index 1f12a0bf..84fe7a0e 100644 --- a/btclib/psbt/psbt_in.py +++ b/btclib/psbt/psbt_in.py @@ -126,7 +126,7 @@ def _deserialize_final_script_witness(k: bytes, v: bytes) -> Witness: def _assert_valid_ripemd160_preimages( - ripemd160_preimages: Mapping[bytes, bytes] + ripemd160_preimages: Mapping[bytes, bytes], ) -> None: for h, preimage in ripemd160_preimages.items(): if ripemd160(preimage) != h: @@ -200,8 +200,9 @@ def __init__( taproot_key_spend_signature: Octets = b"", taproot_script_spend_signatures: Mapping[Octets, Octets] | None = None, taproot_leaf_scripts: Mapping[Octets, tuple[Octets, int]] | None = None, - taproot_hd_key_paths: Mapping[Octets, tuple[list[Octets], BIP32KeyOrigin]] - | None = None, + taproot_hd_key_paths: ( + Mapping[Octets, tuple[list[Octets], BIP32KeyOrigin]] | None + ) = None, taproot_internal_key: Octets = b"", taproot_merkle_root: Octets = b"", unknown: Mapping[Octets, Octets] | None = None, @@ -283,12 +284,12 @@ def to_dict(self, check_validity: bool = True) -> dict[str, Any]: self.assert_valid() return { - "non_witness_utxo": self.non_witness_utxo.to_dict(False) - if self.non_witness_utxo - else None, - "witness_utxo": self.witness_utxo.to_dict(False) - if self.witness_utxo - else None, + "non_witness_utxo": ( + self.non_witness_utxo.to_dict(False) if self.non_witness_utxo else None + ), + "witness_utxo": ( + self.witness_utxo.to_dict(False) if self.witness_utxo else None + ), "partial_signatures": encode_dict_bytes_bytes(self.partial_sigs), "sig_hash": self.sig_hash_type, # TODO make it { "asm": "", "hex": "" } @@ -327,12 +328,16 @@ def from_dict( decode_from_bip32_derivs(dict_["taproot_hd_key_paths"]), ) return cls( - Tx.from_dict(dict_["non_witness_utxo"], False) - if dict_["non_witness_utxo"] - else None, - TxOut.from_dict(dict_["witness_utxo"], False) - if dict_["witness_utxo"] - else None, + ( + Tx.from_dict(dict_["non_witness_utxo"], False) + if dict_["non_witness_utxo"] + else None + ), + ( + TxOut.from_dict(dict_["witness_utxo"], False) + if dict_["witness_utxo"] + else None + ), dict_["partial_signatures"], dict_["sig_hash"], dict_["redeem_script"], diff --git a/btclib/psbt/psbt_out.py b/btclib/psbt/psbt_out.py index f09bb5fe..2610e568 100644 --- a/btclib/psbt/psbt_out.py +++ b/btclib/psbt/psbt_out.py @@ -80,8 +80,9 @@ def __init__( hd_key_paths: Mapping[Octets, BIP32KeyOrigin] | None = None, taproot_internal_key: Octets = b"", taproot_tree: Sequence[tuple[int, int, Octets]] | None = None, - taproot_hd_key_paths: Mapping[Octets, tuple[list[bytes], BIP32KeyOrigin]] - | None = None, + taproot_hd_key_paths: ( + Mapping[Octets, tuple[list[bytes], BIP32KeyOrigin]] | None + ) = None, unknown: Mapping[Octets, Octets] | None = None, check_validity: bool = True, ) -> None: diff --git a/btclib/psbt/psbt_utils.py b/btclib/psbt/psbt_utils.py index fde85cca..9872dfad 100644 --- a/btclib/psbt/psbt_utils.py +++ b/btclib/psbt/psbt_utils.py @@ -96,7 +96,7 @@ def serialize_dict_bytes_bytes( def encode_leaf_scripts( - dict_: Mapping[bytes, tuple[bytes, int]] + dict_: Mapping[bytes, tuple[bytes, int]], ) -> dict[str, tuple[str, int]]: """Return the json representation of a tap_leaf_script. @@ -107,7 +107,7 @@ def encode_leaf_scripts( def decode_leaf_scripts( - map_: Mapping[Octets, tuple[Octets, int]] | None + map_: Mapping[Octets, tuple[Octets, int]] | None, ) -> dict[bytes, tuple[bytes, int]]: """Return a tap_leaf_script from its json representation.""" if map_ is None: @@ -136,7 +136,7 @@ def parse_leaf_script(v: bytes) -> tuple[bytes, int]: def encode_taproot_tree( - list_: list[tuple[int, int, bytes]] + list_: list[tuple[int, int, bytes]], ) -> list[tuple[int, int, str]]: """Return the json representation of a tap_tree. @@ -146,7 +146,7 @@ def encode_taproot_tree( def decode_taproot_tree( - list_: Sequence[tuple[int, int, Octets]] | None + list_: Sequence[tuple[int, int, Octets]] | None, ) -> list[tuple[int, int, bytes]]: """Return a tap_tree from its json representation.""" if list_ is None: @@ -184,7 +184,7 @@ def parse_taproot_tree(v: bytes) -> list[tuple[int, int, bytes]]: def taproot_bip32_to_dict( - taproot_hd_key_paths: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]] + taproot_hd_key_paths: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]], ) -> list[dict[str, Any]]: """Return the json representation of a tap_bip32_derivation. @@ -203,7 +203,7 @@ def taproot_bip32_to_dict( def taproot_bip32_from_dict( - taproot_hd_key_paths: list[dict[str, str]] + taproot_hd_key_paths: list[dict[str, str]], ) -> dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]: """Return a tap_bip32_derivation from its json representation.""" return { @@ -219,7 +219,7 @@ def taproot_bip32_from_dict( def decode_taproot_bip32( - dict_: Mapping[Octets, tuple[Sequence[Octets], BIP32KeyOrigin]] | None + dict_: Mapping[Octets, tuple[Sequence[Octets], BIP32KeyOrigin]] | None, ) -> dict[bytes, tuple[list[bytes], BIP32KeyOrigin]]: """Parse correctly the tap_bip32_derivation init arguments.""" if dict_ is None: @@ -315,7 +315,7 @@ def assert_valid_taproot_tree(tree: list[tuple[int, int, bytes]]) -> None: def assert_valid_taproot_bip32_derivation( - derivations: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]] + derivations: dict[bytes, tuple[list[bytes], BIP32KeyOrigin]], ) -> None: """Fails when the public keys have not the correct length.""" for pubkey in derivations: diff --git a/btclib/tx/tx.py b/btclib/tx/tx.py index 58da44ac..9b937dfc 100644 --- a/btclib/tx/tx.py +++ b/btclib/tx/tx.py @@ -224,11 +224,14 @@ def serialize(self, include_witness: bool, check_validity: bool = True) -> bytes b"".join(tx_in.serialize(check_validity) for tx_in in self.vin), var_int.serialize(len(self.vout)), b"".join(tx_out.serialize(check_validity) for tx_out in self.vout), - b"".join( - tx_in.script_witness.serialize(check_validity) for tx_in in self.vin - ) - if segwit - else b"", + ( + b"".join( + tx_in.script_witness.serialize(check_validity) + for tx_in in self.vin + ) + if segwit + else b"" + ), self.lock_time.to_bytes(4, byteorder="little", signed=False), ] ) diff --git a/btclib/var_int.py b/btclib/var_int.py index bf261e57..7ca5a8ac 100644 --- a/btclib/var_int.py +++ b/btclib/var_int.py @@ -58,9 +58,9 @@ def serialize(i: int) -> bytes: if i < 0xFD: # 1 byte return bytes([i]) if i <= 0xFFFF: # 2 bytes - return b"\xFD" + i.to_bytes(2, byteorder="little", signed=False) + return b"\xfd" + i.to_bytes(2, byteorder="little", signed=False) if i <= 0xFFFFFFFF: # 4 bytes - return b"\xFE" + i.to_bytes(4, byteorder="little", signed=False) + return b"\xfe" + i.to_bytes(4, byteorder="little", signed=False) if i <= 0xFFFFFFFFFFFFFFFF: # 8 bytes - return b"\xFF" + i.to_bytes(8, byteorder="little", signed=False) + return b"\xff" + i.to_bytes(8, byteorder="little", signed=False) raise BTClibValueError(f"integer too big for var_int encoding: '{hex_string(i)}'") diff --git a/tests/bip32/test_bip32.py b/tests/bip32/test_bip32.py index 433eb9ca..f631c01f 100644 --- a/tests/bip32/test_bip32.py +++ b/tests/bip32/test_bip32.py @@ -44,7 +44,7 @@ def test_exceptions() -> None: seed = "5b56c417303faa3fcba7e57400e120a0" with pytest.raises(BTClibValueError, match="unknown extended key version: "): - version = b"\x04\x88\xAD\xE5" + version = b"\x04\x88\xad\xe5" rootxprv_from_seed(seed, version) with pytest.raises(BTClibValueError, match="too many bits for seed: "): diff --git a/tests/script/test_script.py b/tests/script/test_script.py index 5e3ec54a..a1efdaeb 100644 --- a/tests/script/test_script.py +++ b/tests/script/test_script.py @@ -60,15 +60,15 @@ def test_op_int() -> None: def test_serialize_bytes_command() -> None: length = 75 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 1 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 2 length = 255 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 2 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 3 diff --git a/tests/script/test_taproot.py b/tests/script/test_taproot.py index 0824982f..094c24fc 100644 --- a/tests/script/test_taproot.py +++ b/tests/script/test_taproot.py @@ -145,15 +145,15 @@ def test_serialize_op_success() -> None: def test_serialize_bytes_command() -> None: length = 75 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 1 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 2 length = 255 - b = b"\x0A" * length + b = b"\x0a" * length assert len(serialize([b])) == length + 2 - b = b"\x0A" * (length + 1) + b = b"\x0a" * (length + 1) assert len(serialize([b])) == (length + 1) + 3 diff --git a/tests/test_bech32.py b/tests/test_bech32.py index 7eaf639d..8e989dba 100644 --- a/tests/test_bech32.py +++ b/tests/test_bech32.py @@ -72,7 +72,7 @@ def test_bech32() -> None: invalid_checksum = [ ["\x20" + " 1nwldj5", r"HRP character out of range: *"], - ["\x7F" + "1axkwrx", r"HRP character out of range: *"], + ["\x7f" + "1axkwrx", r"HRP character out of range: *"], ["\x80" + "1eym55h", r"HRP character out of range: *"], ["pzry9x0s0muk", r"no separator character: *"], ["1pzry9x0s0muk", r"empty HRP: *"], @@ -129,7 +129,7 @@ def test_bech32m() -> None: invalid_checksum = [ ["\x20" + "1xj0phk", r"HRP character out of range: *"], - ["\x7F" + "1g6xzxy", r"HRP character out of range: *"], + ["\x7f" + "1g6xzxy", r"HRP character out of range: *"], ["\x80" + "1vctc34", r"HRP character out of range: *"], ["qyrz8wqd2c9m", r"no separator character: *"], ["1qyrz8wqd2c9m", r"empty HRP: *"],