libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.61k stars 385 forks source link

add Object.__eq__ and Object.__hash__ #802

Open chadrik opened 6 years ago

chadrik commented 6 years ago

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.

jdavid commented 6 years ago

Yes please. Thanks!

imbuedhope commented 5 years ago

I'm pretty sure I added support for this with #853 (the previous on this topic issue was #852) Are you using the latest version of pygit2?