-
Notifications
You must be signed in to change notification settings - Fork 9
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 __eq__ and __hash__ methods for LedgerAccount #51
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the PR! This is useful.
Linting is failing though. Can you please run python setup.py lint
to take care of it? After that I'll probably merge after some brief testing.
@@ -180,6 +180,13 @@ def __init__(self, path, address): | |||
def __repr__(self): | |||
return f"<ledgereth.objects.LedgerAccount {self.address}>" | |||
|
|||
def __eq__(self, other): | |||
if isinstance(other, LedgerAccount): | |||
return self.path == other.path and self.address == other.address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Why compare path here? The odds of an address collision with a different path are all but impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you when LedgerAccount
is calculated from Ledger, but the class itself let you create different instances with the same address and different path, this instances shouldn't be equal between them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you run into this IRL? If so, under what circumstances?
Not asking for any changes, just trying to understand this so I don't introduce a regression unintentionally down the road.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't faced this scenario in real life. As far as I know, this could occur only if two ledgers are connected simultaneously, which isn't possible with the current implementation or someone manually initializes the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it, two ledgers shouldn't return the same address. I think the unique situation where this could happen is instantiating manually.
Done :) |
Thanks for your contribution. I'll probably have a release tonight. |
Closes #50
This PR defines
__eq__
and__hash__
methods onLedgerAccount
class to makes possible that instances ofLedgerAccount
with the samepath
andaddress
were evaluated as equals.