mendeleev
mendeleev copied to clipboard
Remove hash support since it is unsafe for mutable objects
Allowing hash on mutable objects leads to strange situations. For example:
>>> import mendeleev
>>> H = mendeleev.element(1)
>>> myset = {H}
>>> H.atomic_weight = 2
>>> H in myset
False
>>> H in list(myset)
True
This PR remove the hashing support so that instead we get an error:
>>> import mendeleev
>>> H = mendeleev.element(1)
>>> myset = {H}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'Element'
If you need to place elements or dict or set, you can use the .atomic_number property instead.
>>> import mendeleev
>>> H = mendeleev.element(1)
>>> myset = {H.atomic_number}
>>> H.atomic_number in myset
True
>>> H.atomic_number in list(myset)
True
Can you point me to where hash is called on a mutable object in mendeleev?
Can you point me to where
hashis called on a mutable object in mendeleev?
Nowhere but other code using the library might start to put elements in a dict or set.