I think this functionality is builtin to dictionaries, if you try to access an invalid key it'll raise a `KeyError`.

So in your calling code you can import _unit_names directly and say:
```python
try:
    foo = _unit_names[bar]
except KeyError:
    raise

It should be faster too, because I think `abbrev in _unit_names` will implicitly get the keys and loop over them.