astropy/astropy — pull request #2382 by mdboom (2014-05-09 18:30:47+00:00)
Title: The identity of composite and irreducible units does not match.

I'm having a problem where I have constructed a composite unit out of what should be an irreducible unit. I think the best way to explain this issue is by example:

```
In [1]: import astropy.units as u

In [2]: composite_unit = u.s.compose(units=[u.Unit("s")])[0]

In [3]: type(composite_unit)
Out[3]: astropy.units.core.CompositeUnit

In [4]: composite_unit == u.s
Out[4]: True

In [5]: composite_unit is u.s
Out[5]: False

In [6]: composite_unit in [u.s]
Out[6]: True

In [7]: composite_unit in set([u.s])
Out[7]: False

In [8]: composite_unit
Out[8]: Unit("s")

In [9]: composite_unit.compose(units=[u.s])
Out[9]: [Unit("s")]

In [10]: u.s.compose(units=[composite_unit])
ERROR: UnitsError: Cannot represent unit s in terms of the given units [astropy.units.core]
```

This is normally not a problem, as CompositeUnit and IrreduceableUnit are ``==`` to each other. But because ``set()`` uses identity, and ``list()`` uses equality, this behavior can be really confusing.

This isn't a show-stopper for me (I found it because I had some old code using ``.compose()`` instead of ``.decompose()``, since ``.decompose()`` was broken for a few versions), but it is an edge case that I think should be addressed.