Skip to content

Commit

Permalink
fix: correct dict keys for nested tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed May 4, 2024
1 parent 0620d2e commit 750567c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions brownie/convert/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,23 @@ def __new__(cls, values: Sequence, abi: Optional[List] = None) -> "ReturnValue":
values[i] = ReturnValue(values[i], abi[i]["components"])
else:
# array of tuples
values[i] = ReturnValue(values[i], [abi[i]] * len(values[i]))
inner_abi = abi[i].copy()
inner_abi["type"] = inner_abi["type"].rsplit("[", maxsplit=1)[0]
final_abi = [deepcopy(inner_abi) for i in range(len(values[i]))]
if inner_abi.get("name"):
name = inner_abi["name"]
for x in range(len(final_abi)):
final_abi[x]["name"] = f"{name}[{x}]"

values[i] = ReturnValue(values[i], final_abi)
else:
# array
values[i] = ReturnValue(values[i])

self = super().__new__(cls, values) # type: ignore
self._abi = abi or []
self._dict = {i["name"]: values[c] for c, i in enumerate(self._abi) if i["name"]}
self._dict = {i.get("name", "") or f"arg[{c}]": values[c] for c, i in enumerate(self._abi)}

return self

def __hash__(self) -> int:
Expand Down Expand Up @@ -349,7 +358,13 @@ def count(self, value: Any) -> int:

def dict(self) -> Dict:
"""ReturnValue.dict() -> a dictionary of ReturnValue's named items"""
return self._dict # type: ignore
response = {}
for k, v in self._dict.items():
if isinstance(v, ReturnValue) and v._abi:
response[k] = v.dict()
else:
response[k] = v
return response

def index(self, value: Any, start: int = 0, stop: Any = None) -> int:
"""ReturnValue.index(value, [start, [stop]]) -> integer -- return first index of value.
Expand Down

0 comments on commit 750567c

Please sign in to comment.