Skip to content

add Object.__eq__ and Object.__hash__ #802

Open
@chadrik

Description

@chadrik

It would be intuitive if this worked:

r = Repository('.git')
r['103ea4507a9df26a19388cd4115c8bfd1fb784af'] == r['103ea4507a9df26a19388cd4115c8bfd1fb784af']

I'd like to add a __eq__ method to Object which compares the underlying Oid object held by the id attribute.

Additionally, since this this attribute is read-only Objects are effectively immutable, thus it would be great to have a __hash__ method (which returns hash(self.id)) so that Objects can be placed in sets and used as keys in dictionaries.

I'm happy to make the PR for this if you think it makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions