Create self._hooks in __init__ to allow delayed calls to init_app()#27
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A useful pattern with Flask extensions is to instantiate the extension in
a separate module, then import that in wsgi.py, calling ext.init_app(app)
there. This way, in the case of github_webhook e.g., webhooks can be defined
(decorated) in a separate module, before the Flask app has even been created.
For this to work, however, self._hooks (which is used by the decorator) must
be defined even if no app was given at instantiationtime. Previously, it was
only being created as part of init_app().
This commit:
creates self._hooks early, in Webhook.init
defines self.app in init_app(), so that it does not stay as None if
init_app() is called in a delayed fashion.
On the other hand, self._logger is kept in init_app(), so that Flask's log
system has had a chance to initialize. It is not used by the decorator.
Signed-off-by: Dato Simó dato@net.com.org.es