-
Notifications
You must be signed in to change notification settings - Fork 123
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
Equality of pystac objects? #380
Comments
I'm in favor of defining equality for PySTAC objects. As I started working on an I can tackle this as part of the work on #371. It sounds like we should raise a def __eq__(self, other: object) -> bool:
if type(self) != type(other):
raise NotImplementedError(f"Type of other must be {type(self)}"
return self.to_dict() == other.to_dict()
def __ne__(self, other: object) -> bool:
if type(self) != type(other):
raise NotImplementedError(f"Type of other must be {type(self)}"
return self.to_dict() != other.to_dict() That article mentions that Python 3 automatically makes objects unhashable if you define |
I haven't read closely, but I want to confirm: do you want How to handle "foreign" objects is a really tricky subject, but I think the best practice is to only consider your own types and to return |
Yes, thanks for pointing that out, I misread that. We want to return |
It might be worth a little more discussion on how we want to specifically define equality. I'm realizing now that the above definition won't necessarily work in an It seems like there could be a use-case for considering otherwise identical Items that belong to different Catalogs or Collections to be equal. In that case, if the |
cc: @gadomski |
In writing tests for #379, I stumbled over Asset objects not defining
__eq__
.Looking briefly, I don't see it for any of the core items (a couple extensions define
__eq__
). The behavior of Python is to fall back to object identity, (a is b
).Should pystac objects define
__eq__
(and__ne__
)? An implementation like the following probably makes sense:If we define
__eq__
then we may need to make the objects unhashable, since the objects are mutable. https://hynek.me/articles/hashes-and-equality/ is a good read on this.The text was updated successfully, but these errors were encountered: