Ensure hashability of classes with custom equality check.
The issue has been noticed because Yelp/swagger-spec-compatibility tests are broken (due to the fact that bravado_core.spec.Spec instances are not hashable).
In #360 equality methods have been added in order to increase testing coverage of deepcopy of instances.
Objects inheriting from object (aka all) have:
__eq__ implemented as always returning False
__hash__ implemented as returning a unique identifier of the specific instance (aka result of id)
Unfortunately, on Python, if you override one __eq__ method then the "default" __hash__ implementation is not is use, and so to make the object hashable again you need to implement __hash__ yourself (what this CR does). (Documentation reference)
Coverage increased (+0.006%) to 98.508% when pulling 4807fb5c4d611e0ef5c021bc826d098944dd9cee on macisamuele:maci-ensure-hashability into 9c20a251f016870f1f716b7217d3dae4ebbf9c56 on Yelp:master.
Ensure hashability of classes with custom equality check.
The issue has been noticed because Yelp/swagger-spec-compatibility tests are broken (due to the fact that
bravado_core.spec.Spec
instances are not hashable).In #360 equality methods have been added in order to increase testing coverage of deepcopy of instances.
Objects inheriting from
object
(aka all) have:__eq__
implemented as always returningFalse
__hash__
implemented as returning a unique identifier of the specific instance (aka result ofid
)Unfortunately, on Python, if you override one
__eq__
method then the "default"__hash__
implementation is not is use, and so to make the object hashable again you need to implement__hash__
yourself (what this CR does). (Documentation reference)