Would it make more sense to do this test inside the `except KeyError` clause, as it's only there that the code paths diverge?