-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Milestone
Description
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:
>>> a.value = 6
>>> c
{<Quantity 6 s>: 'foo', <Quantity 6 s>: 'bar'}
>>> c[a]
'bar'
>>> c[b]
'bar'
Metadata
Metadata
Assignees
Labels
No labels