py: Use __hash__ method if a type defines it
tests: Add test for hash of user defined class.