Skip to content

Commit

Permalink
Use assert_type alongside cast (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn authored Jan 21, 2025
1 parent a83b0d0 commit e122ca6
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/arrow_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/berlin/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/byzantium/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/cancun/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/constantinople/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/dao_fork/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/frontier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/gray_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/homestead/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/istanbul/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/london/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/muir_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/paris/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/shanghai/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/spurious_dragon/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)
3 changes: 2 additions & 1 deletion src/ethereum/tangerine_whistle/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tuple,
TypeVar,
Union,
assert_type,
cast,
)

Expand Down Expand Up @@ -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,
)

0 comments on commit e122ca6

Please sign in to comment.