You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Quantity is mutable but defines a __hash__ method #761
The astropy.units.Quantity class is mutable because its value and unit properties both have setters, but it also declares a __hash__ method. Usually, only immutable objects should be hashable.
Here are two distinct Quantities:
>>> from astropy import units as u
>>> a = 5 * u.second
>>> b = 6 * u.second
And here they are as keys of a dictionary:
>>> c = {a: 'foo', b: 'bar'}
>>> c
{<Quantity 5 s>: 'foo', <Quantity 6 s>: 'bar'}
Since the two Quantities are mutable, we can change the properties of one of them to make them equal and render one of the dictionary values inaccessible:
Activity
mdboom commentedon Feb 11, 2013
Did we mean for it to be mutable? I recall some discussion (that I can't currently find) that it would be best if they were immutable.
lpsinger commentedon Feb 11, 2013
@mdboom, there is some discussion of the
__hash__implementation in #445.astrofrog commentedon Feb 11, 2013
It looks like we all agreed in #445 that
Quantityshould be immutable, so it must have been an oversight. It should be fixed to be made immutable.Removed value setter to make Quantity immutable
eteq commentedon Feb 11, 2013
See #762 - that removes the
valuesetter (looks like there already was no setter forunit).astrofrog commentedon Feb 12, 2013
Can be closed once #762 is merged.
eteq commentedon Feb 12, 2013
Actually, it should get closed automatically after merge, because I put "Closes #761" in one of the commit messages. We'll see if it works...
eteq commentedon Feb 12, 2013
And so it did. Yay github!