From 501b6bf67094f90f69bc21bcd62494d557682e10 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Mon, 20 Jan 2025 15:45:48 -0500 Subject: [PATCH] Use assert_type alongside cast --- setup.cfg | 2 +- src/ethereum/arrow_glacier/trie.py | 3 ++- src/ethereum/berlin/trie.py | 3 ++- src/ethereum/byzantium/trie.py | 3 ++- src/ethereum/cancun/trie.py | 3 ++- src/ethereum/constantinople/trie.py | 3 ++- src/ethereum/dao_fork/trie.py | 3 ++- src/ethereum/frontier/trie.py | 3 ++- src/ethereum/gray_glacier/trie.py | 3 ++- src/ethereum/homestead/trie.py | 3 ++- src/ethereum/istanbul/trie.py | 3 ++- src/ethereum/london/trie.py | 3 ++- src/ethereum/muir_glacier/trie.py | 3 ++- src/ethereum/paris/trie.py | 3 ++- src/ethereum/shanghai/trie.py | 3 ++- src/ethereum/spurious_dragon/trie.py | 3 ++- src/ethereum/tangerine_whistle/trie.py | 3 ++- 17 files changed, 33 insertions(+), 17 deletions(-) diff --git a/setup.cfg b/setup.cfg index 730939c928..53b30f6759 100644 --- a/setup.cfg +++ b/setup.cfg @@ -113,7 +113,7 @@ python_requires = >=3.10 install_requires = pycryptodome>=3,<4 coincurve>=20,<21 - typing_extensions>=4 + typing_extensions>=4.2 py_ecc @ git+https://github.com/petertdavies/py_ecc.git@127184f4c57b1812da959586d0fe8f43bb1a2389 ethereum-types>=0.2.1,<0.3 diff --git a/src/ethereum/arrow_glacier/trie.py b/src/ethereum/arrow_glacier/trie.py index 57dccead3f..8672584f5b 100644 --- a/src/ethereum/arrow_glacier/trie.py +++ b/src/ethereum/arrow_glacier/trie.py @@ -33,6 +33,7 @@ from ethereum_types.bytes import Bytes from ethereum_types.frozen import slotted_freezable from ethereum_types.numeric import U256, Uint +from typing_extensions import assert_type from ethereum.crypto.hash import keccak256 from ethereum.london import trie as previous_trie @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/berlin/trie.py b/src/ethereum/berlin/trie.py index 4a8e9c373a..105b5e27b7 100644 --- a/src/ethereum/berlin/trie.py +++ b/src/ethereum/berlin/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/byzantium/trie.py b/src/ethereum/byzantium/trie.py index d3f3808680..26cbb0cc14 100644 --- a/src/ethereum/byzantium/trie.py +++ b/src/ethereum/byzantium/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/cancun/trie.py b/src/ethereum/cancun/trie.py index ed41209723..ce1bb3df07 100644 --- a/src/ethereum/cancun/trie.py +++ b/src/ethereum/cancun/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -488,6 +489,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/constantinople/trie.py b/src/ethereum/constantinople/trie.py index bc29414882..c94e1ef8db 100644 --- a/src/ethereum/constantinople/trie.py +++ b/src/ethereum/constantinople/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/dao_fork/trie.py b/src/ethereum/dao_fork/trie.py index ab2263892c..5a1cdeeb94 100644 --- a/src/ethereum/dao_fork/trie.py +++ b/src/ethereum/dao_fork/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/frontier/trie.py b/src/ethereum/frontier/trie.py index 2f4982a819..64cefbc933 100644 --- a/src/ethereum/frontier/trie.py +++ b/src/ethereum/frontier/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -486,6 +487,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/gray_glacier/trie.py b/src/ethereum/gray_glacier/trie.py index b4c92a75e9..0e216325f5 100644 --- a/src/ethereum/gray_glacier/trie.py +++ b/src/ethereum/gray_glacier/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/homestead/trie.py b/src/ethereum/homestead/trie.py index 7e190ddb68..e9affa74a7 100644 --- a/src/ethereum/homestead/trie.py +++ b/src/ethereum/homestead/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/istanbul/trie.py b/src/ethereum/istanbul/trie.py index eb985c1b3d..6a222f92ec 100644 --- a/src/ethereum/istanbul/trie.py +++ b/src/ethereum/istanbul/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/london/trie.py b/src/ethereum/london/trie.py index 44d2cc0c54..546a17bc0b 100644 --- a/src/ethereum/london/trie.py +++ b/src/ethereum/london/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/muir_glacier/trie.py b/src/ethereum/muir_glacier/trie.py index 2e07eec683..05b31a5150 100644 --- a/src/ethereum/muir_glacier/trie.py +++ b/src/ethereum/muir_glacier/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/paris/trie.py b/src/ethereum/paris/trie.py index 7f7febfab0..5f27a6ff04 100644 --- a/src/ethereum/paris/trie.py +++ b/src/ethereum/paris/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/shanghai/trie.py b/src/ethereum/shanghai/trie.py index 90f366854c..f2ca34c080 100644 --- a/src/ethereum/shanghai/trie.py +++ b/src/ethereum/shanghai/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -488,6 +489,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/spurious_dragon/trie.py b/src/ethereum/spurious_dragon/trie.py index 29e3aaf01e..d7460d1995 100644 --- a/src/ethereum/spurious_dragon/trie.py +++ b/src/ethereum/spurious_dragon/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, ) diff --git a/src/ethereum/tangerine_whistle/trie.py b/src/ethereum/tangerine_whistle/trie.py index 1fcb986233..d47bc069c9 100644 --- a/src/ethereum/tangerine_whistle/trie.py +++ b/src/ethereum/tangerine_whistle/trie.py @@ -27,6 +27,7 @@ Tuple, TypeVar, Union, + assert_type, cast, ) @@ -485,6 +486,6 @@ def patricialize( for k in range(16) ) return BranchNode( - cast(BranchSubnodes, subnodes), + cast(BranchSubnodes, assert_type(subnodes, Tuple[rlp.Extended, ...])), value, )