I have a class called WeakBoundMethod (source on codereview.se). I’d like some guidelines about how I should implement __hash__(). Also, Python 3 automatically provides a __repr__() function, so I guess I shouldn’t bother redefining it then (?). What about __str__(), which I understand is a human readable text representation of the object; should I define that as well? any guidelines?
About the hashing function…
I’d like it to generate the hash based on the __self__ and __func__ of the bound method it is wrapping. How can I do that?
If in doubt, don’t implement magic methods. The defaults are there for a reason and will be fine. In your case, it’s completely unnecessary to implement
__hash__(and if you would implement it, you’d have to implement__eq__as well) unless you expect someone to have a set or dictionary of methods.__str__can be useful. In your case, its result should include:str()result to identify the function, say, by name