Implement InputSource and OutputSource equality and hash methods
Here we are after moulte types errors!!
Implementation
In Silkaj, I need to check the equality of InputSource
:
-
__eq__()
implementation, to allow:inputsource1 == inputsource2
-
__hash__()
methods should also be implemented. As I understood, it allows those classes stored intodict()
andset()
to continue working properly. -
I also did it for
OutputSource
, as it’s pretty similar.
Readings
- https://hynek.me/articles/hashes-and-equality/
- https://stackoverflow.com/questions/390250/elegant-ways-to-support-equivalence-equality-in-python-classes
- https://medium.com/@s16h/pythons-notimplemented-type-2d720137bf41
Types
I don’t if we can handle the type of the other
argument. I tried, but I think it’s already checked with following block:
if not isinstance(other, InputSource):
return NotImplemented
In current code I found Any
, and object
.
One commit to change the return value within the equality method when it is not implemented between two different classes from False
to NotImplemented
.
Release
We can either wait for 0.54, or I can take care to release a 0.53.1.
Edited by Moul