If happen that someone use this file directly this can be a problem. IMHO add

~~~
else:
    raise KeyError(...)
~~~

at the end of the `if` is a good thing.