libgit2 / pygit2

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

Improve repr of pygit2.hash #1215

Open jfine2358 opened 1 year ago

jfine2358 commented 1 year ago

At present hash and pygit2.hash have the same repr. We can tell them apart by looking at the __module__ attribute. But not their type.

Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygit2
>>> hash, pygit2.hash
(<built-in function hash>, <built-in function hash>)
>>> id(hash) - id(pygit2.hash)
2918112
>>> pygit2.hash.__module__
'pygit2._pygit2'
>>> hash.__module__
'builtins'
>>> type(hash), type(pygit2.hash)
(<class 'builtin_function_or_method'>, <class 'builtin_function_or_method'>)
>>> 

This will confuse anyone who relies on repr to check that they are using the correct hash function.