libgit2 / libgit2/pygit2

add Object.__eq__ and Object.__hash__

Open
#802 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
1.7k
Forks
408
Avg merge
2d 57m
Merged PRs (30d)
7

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Object entry point and its read-only id attribute, then inspect how Repository lookups produce objects. Verify the requested equality and hashing behavior using the Repository('.git') example, including that objects can be placed in sets and used as dictionary keys.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, python
Domain
backend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.