Support async template context processors

This is useful as there is contextual information that could be loaded
via IO e.g. information from a database. This also matches Quart and
hence makes the shared signature easier to manage.
This commit is contained in:
pgjones 2023-07-15 23:21:12 +01:00
parent 72c85e80c8
commit 3f6b243cec
2 changed files with 5 additions and 2 deletions

View file

@ -478,7 +478,7 @@ class Flask(App):
for name in names:
if name in self.template_context_processors:
for func in self.template_context_processors[name]:
context.update(func())
context.update(self.ensure_sync(func)())
context.update(orig_ctx)

View file

@ -61,7 +61,10 @@ TeardownCallable = t.Union[
t.Callable[[t.Optional[BaseException]], None],
t.Callable[[t.Optional[BaseException]], t.Awaitable[None]],
]
TemplateContextProcessorCallable = t.Callable[[], t.Dict[str, t.Any]]
TemplateContextProcessorCallable = t.Union[
t.Callable[[], t.Dict[str, t.Any]],
t.Callable[[], t.Awaitable[t.Dict[str, t.Any]]],
]
TemplateFilterCallable = t.Callable[..., t.Any]
TemplateGlobalCallable = t.Callable[..., t.Any]
TemplateTestCallable = t.Callable[..., bool]