Add __contains__ to State

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 in keyword.

class State(object):

    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()

Wouldn’t it be be as effective to catch AttributeError?

It would be possible to do it that way, yeah. But as effective, I disagree. The exception has to be constructed, and that includes gathering the stack trace and such.

Also for reading comprehension, compare the two following snippets:

except AttribugeError: = DB()
if "db" not in = DB()


I find the second one much more readable.