Skip to content

Commit c898a5b

Browse files
committed
Support partially named method arguments
1 parent e34cdbf commit c898a5b

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ Added
99
^^^^^
1010

1111
- Support for contract errors with anonymous fields. (PR_90_)
12+
- Support for partially named method arguments. (PR_91_)
1213

1314

1415
.. _PR_90: https://github.com/fjarri-eth/pons/pull/90
16+
.. _PR_91: https://github.com/fjarri-eth/pons/pull/91
1517

1618

1719
0.10.0 (2025-10-19)

pons/_abi_types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ def dispatch_types(abi_entry: ABI_JSON) -> list[Type] | dict[str, Type]:
512512

513513
names = [entry["name"] for entry in abi_entry_typed]
514514

515-
# Unnamed arguments; treat as positional arguments
516-
if names and all(not name for name in names):
515+
# In Solidity, it is possible to have have an argument list like `(address x, uint256)`
516+
# (that is, only some of the arguments are unnamed).
517+
# This cannot be mapped to Python function signatures,
518+
# so we have to treat this as if all the arguments were unnamed.
519+
if names and any(not name for name in names):
517520
return [dispatch_type(entry) for entry in abi_entry_typed]
518521

519-
if any(not name for name in names):
520-
raise ValueError("Arguments must be either all named or all unnamed")
521-
522522
# Since we are returning a dictionary, need to be sure we don't silently merge entries
523523
if len(names) != len(set(names)):
524524
raise ValueError("All ABI entries must have distinct names")

tests/test_abi_types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,11 @@ def test_dispatch_types() -> None:
256256
# For an empty argument list we choose to resolve it as an empty dictionary, for certainty.
257257
assert dispatch_types([]) == {}
258258

259-
with pytest.raises(ValueError, match="Arguments must be either all named or all unnamed"):
260-
dispatch_types([dict(name="foo", type="uint8"), dict(name="", type="uint16[2]")])
259+
# Partially named arguments
260+
assert dispatch_types([dict(name="x", type="uint8"), dict(name="", type="uint16[2]")]) == [
261+
abi.uint(8),
262+
abi.uint(16)[2],
263+
]
261264

262265
with pytest.raises(ValueError, match="All ABI entries must have distinct names"):
263266
dispatch_types([dict(name="foo", type="uint8"), dict(name="foo", type="uint16[2]")])

0 commit comments

Comments
 (0)