Skip to content

Commit

Permalink
refactor: use contextlib.suppress (#3419)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alc-Alc authored Apr 23, 2024
1 parent 63d338a commit 7814d59
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions litestar/plugins/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from contextlib import suppress
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Mapping

Expand Down Expand Up @@ -45,16 +46,12 @@ def on_app_init(self, app_config: AppConfig) -> AppConfig:
Returns:
The application configuration with the message callable registered.
"""
template_callable: Callable[[Any], Any]
try:
template_callable: Callable[[Any], Any] = get_flashes
with suppress(MissingDependencyException):
from litestar.contrib.minijinja import MiniJinjaTemplateEngine, _transform_state
except MissingDependencyException: # pragma: no cover
template_callable = get_flashes
else:

if isinstance(self.config.template_config.engine_instance, MiniJinjaTemplateEngine):
template_callable = _transform_state(get_flashes)
else:
template_callable = get_flashes

self.config.template_config.engine_instance.register_template_callable("get_flashes", template_callable) # pyright: ignore[reportGeneralTypeIssues]
return app_config
Expand Down

0 comments on commit 7814d59

Please sign in to comment.