Skip to content

Equality of pystac objects? #380

Open
@TomAugspurger

Description

@TomAugspurger

In writing tests for #379, I stumbled over Asset objects not defining __eq__.

In [1]: import pystac

In [2]: pystac.Asset(href='a') == pystac.Asset(href='a')
Out[2]: False

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:

def __eq__(self, other):
    return type(self) == type(other) and self.to_dict() == other.to_dict()

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions