Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug where could not have same field name in struct as method #2010

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading