Skip to content

Commit

Permalink
fix: field method name clash structs (#2010)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Apr 16, 2024
1 parent 25438b6 commit 9dea7d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ape/utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ def reduce(struct) -> tuple:
"values": values,
}

if conflicts := [p for p in properties if p in methods]:
conflicts_str = ", ".join(conflicts)
logger.debug(
"The following methods are unavailable on the struct "
f"due to having the same name as a field: {conflicts_str}"
)
for conflict in conflicts:
del methods[conflict]

struct_def = make_dataclass(
name,
properties,
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/utils/test_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ def test_values(self, struct):
def test_pickle(self, struct):
actual = pickle.dumps(struct)
assert isinstance(actual, bytes)

def test_field_with_same_name_as_method(self):
struct = create_struct(
"MyStruct", (ABIType(name="values", type="string"),), ("output_value_0",)
)
assert struct.values == "output_value_0" # Is the field, not the method.

0 comments on commit 9dea7d9

Please sign in to comment.