Followup to #7502: add __hash__ method and tests.