Skip to content

Commit 8f1443d

Browse files
antazoeyfselmo
authored andcommitted
bugfix: middleware_onion.values() keyerror fix
- fix: sort - fix: sort imports - fix: lint and typecheck - docs: release note
1 parent 1b66d3c commit 8f1443d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

newsfragments/3596.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issue where ``.values()`` raised a ``KeyError`` in ``NamedTupledOnion``

tests/core/datastructures/test_datastructures.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
from web3.datastructures import (
66
AttributeDict,
7+
NamedElementOnion,
78
tupleize_lists_nested,
89
)
10+
from web3.middleware import (
11+
GasPriceStrategyMiddleware,
12+
)
913

1014

1115
def generate_random_value(depth=0, max_depth=3, key_type=None):
@@ -207,3 +211,11 @@ def test_AttributeDict_hashing_backwards_compatibility(input, error):
207211
assert hash(tuple(sorted(input.items()))) == hash(input)
208212
else:
209213
assert hash(tuple(sorted(input.items()))) == hash(input)
214+
215+
216+
def test_NamedElementOnion_values():
217+
middleware = GasPriceStrategyMiddleware(None)
218+
initial_items = [(middleware, "gas_price_strategy")]
219+
named_element_onion = NamedElementOnion(initial_items)
220+
actual = [x for x in named_element_onion.values()]
221+
assert actual == [middleware]

web3/datastructures.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Tuple,
1818
TypeVar,
1919
Union,
20+
ValuesView,
2021
cast,
2122
)
2223

@@ -337,3 +338,6 @@ def __iter__(self) -> Iterator[TKey]:
337338
# This leads to typing issues, so it's better to use
338339
# ``as_tuple_of_middleware()`` to achieve the same result.
339340
return iter(self._reversed_middleware()) # type: ignore
341+
342+
def values(self) -> ValuesView[TValue]:
343+
return ValuesView(self._queue)

0 commit comments

Comments
 (0)