astropy/astropy — pull request #1870 by mdboom (2013-12-06 02:05:52+00:00)
Title: Recommend alternatives when a unit isn't found

This presents helpful exceptions with "closely matched" units (using difflib).

```
In [2]: u.Unit("microns")
ERROR: ValueError: 'microns' did not parse as unit: At col 0, microns is not a valid unit. Did you mean micron? [astropy.units.core]

In [3]: u.Unit("s/microns")
ERROR: ValueError: 's/microns' did not parse as unit: At col 2, microns is not a valid unit. Did you mean micron? [astropy.units.core]

In [4]: u.Unit("M")
ERROR: ValueError: 'M' did not parse as unit: At col 0, M is not a valid unit. Did you mean m? [astropy.units.core]

In [5]: u.Unit("metre")
ERROR: ValueError: 'metre' did not parse as unit: At col 0, metre is not a valid unit. Did you mean meter? [astropy.units.core]

In [6]: u.Unit("angstroms")
ERROR: ValueError: 'angstroms' did not parse as unit: At col 0, angstroms is not a valid unit. Did you mean angstrom? [astropy.units.core]

In [7]: u.Unit("milimeter")
ERROR: ValueError: 'milimeter' did not parse as unit: At col 0, milimeter is not a valid unit. Did you mean millimeter? [astropy.units.core]
```

It also simplifies some unit parsing error messages so they don't contain so much redundant information.

Before:

```
ValueError: 'm/s/s' did not parse as unit format 'generic': Syntax error parsing unit string 'm/s/s'
```

After:

```
ValueError: 'm/s/s' did not parse as unit: Syntax error
```