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

Add __hash__ to BaseAddress #2476

Open
fubuloubu opened this issue Jan 22, 2025 · 1 comment
Open

Add __hash__ to BaseAddress #2476

fubuloubu opened this issue Jan 22, 2025 · 1 comment
Labels
category: feature New feature or request good first issue Good for newcomers help wanted Extra attention is needed size: 1 piece Easy, well-defined, quick to accomplish

Comments

@fubuloubu
Copy link
Member

Describe

Adding __hash__ implementation to BaseAddress allows all derivatives (e.g. ContractInstance, AddressAPI, etc.) to be used as keys in dicts and also added to sets, simplifying downstream logic

Specification

...
from ape.utils import to_int
...

class BaseAddress(BaseInterface):
    ...
    def __hash__(self) -> int:
        return to_int(hexstr=self.address)
    ...

see: https://github.com/ApeWorX/ape/blob/main/src/ape/api/address.py#L19

Dependencies

n/a

@fubuloubu fubuloubu added the category: feature New feature or request label Jan 22, 2025
Copy link

linear bot commented Jan 22, 2025

@fubuloubu fubuloubu added good first issue Good for newcomers help wanted Extra attention is needed size: 1 piece Easy, well-defined, quick to accomplish labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: feature New feature or request good first issue Good for newcomers help wanted Extra attention is needed size: 1 piece Easy, well-defined, quick to accomplish
Projects
None yet
Development

No branches or pull requests

1 participant