Skip to content

Commit

Permalink
fix: check jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Oct 3, 2024
1 parent f53f79b commit 4093d3d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/timeout_executor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from collections import deque
from contextlib import suppress
from importlib.util import find_spec
from typing import TYPE_CHECKING, Any, Callable, Generic, overload

from typing_extensions import ParamSpec, Self, TypeVar, override
Expand All @@ -24,7 +25,7 @@
class TimeoutExecutor(Callback[Any, AnyT], Generic[AnyT]):
"""timeout executor"""

__slots__ = ("_timeout", "_callbacks", "initializer", "use_jinja")
__slots__ = ("_timeout", "_callbacks", "initializer", "_use_jinja")

def __init__(self, timeout: float, *, use_jinja: bool = False) -> None:
self._timeout = timeout
Expand All @@ -37,6 +38,23 @@ def timeout(self) -> float:
"""deadline"""
return self._timeout

@property
def use_jinja(self) -> bool:
"""use jinja"""
return self._use_jinja

@use_jinja.setter
def use_jinja(self, value: bool) -> None:
self._use_jinja = value
if value:
spec = find_spec("jinja2")
if spec is None: # pragma: no cover
error_msg = (
"Please install the dependencies "
"by running 'pip install timeout_executor[jinja]'."
)
raise ImportError(error_msg)

@overload
def apply(
self, func: Callable[P, Awaitable[T]], *args: P.args, **kwargs: P.kwargs
Expand Down

0 comments on commit 4093d3d

Please sign in to comment.