Fix a bug causing bools (and other subclasses) to get incorrectly serialized

Without this fix, bools would be deserialized as ints, e.g. getting a key that was set as `True` would return `1`.

In general, it seems like the right thing to do to make sure we always `get` out exactly the same type that we `set`, without any room for error.