There seems to be no way to check whether state has a key, apart from accessing the internal _state property.
By adding the
__contains__ to State, you would be able to use the
class State(object): --snip-- def __contains__(self, key: typing.Any) -> bool: return key in self._state
This would let you use something like the following snippet
# Initialize DB if db not in app.state: app.state.db = DB()