Skip to content

Should more classes have __eq__ and/or __repr__ #222

@schwehr

Description

@schwehr

Not all classes have __eq__ and __repr__. This was originally mentioned in #218 when I was writing tests for the Link class. It's okay to not have one or both of these in a class, but it's worth a quick discussion. __eq__ is mostly useful for testing. Can/should the __repr__ be something that can be pasted to create an instance of that thing? That seems tough with the structure of pystac.

find pystac -name \*.py | xargs grep '__eq__'
pystac/serialization/identify.py:    def __eq__(self, other):
pystac/serialization/identify.py:        return not self.__eq__(other)

and

find pystac -name \*.py | wc -l
28

find pystac -name \*.py | xargs grep --files-without-match '__repr__' | wc -l
20

find pystac -name \*.py | xargs grep '__repr__'
pystac/collection.py:    def __repr__(self):
pystac/extensions/pointcloud.py:    def __repr__(self):
pystac/extensions/pointcloud.py:    def __repr__(self):
pystac/extensions/label.py:    def __repr__(self):
pystac/extensions/label.py:    def __repr__(self):
pystac/extensions/eo.py:    def __repr__(self):
pystac/extensions/eo.py:    def __repr__(self):
pystac/link.py:    def __repr__(self):
pystac/catalog.py:    def __repr__(self):
pystac/item.py:    def __repr__(self):
pystac/item.py:    def __repr__(self):
pystac/serialization/identify.py:    def __repr__(self):
pystac/serialization/identify.py:    def __repr__(self):

Metadata

Metadata

Assignees

No one assigned

    Labels

    best practiceIssues that should be addressed for compliance with best practices, but that aren't technically bugs

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions