Skip to content

Commit

Permalink
fix: remove more type: ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
hatchet-temporary committed Nov 28, 2024
1 parent 161bbe6 commit c61505e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion hatchet_sdk/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def playground(self, name: str, default: str = None):

return default

def _log(self, line: str) -> (bool, Exception): # type: ignore
def _log(self, line: str) -> tuple[bool, Exception]:
try:
self.event_client.log(message=line, step_run_id=self.stepRunId)
return True, None
Expand Down
29 changes: 12 additions & 17 deletions hatchet_sdk/hatchet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import logging
from typing import Any, Callable, Optional, ParamSpec, Type, TypeVar
from typing import Any, Callable, Optional, Type

from typing_extensions import deprecated

Expand Down Expand Up @@ -32,9 +32,6 @@
WorkflowStepProtocol,
)

P = ParamSpec("P")
R = TypeVar("R")


def workflow(
name: str = "",
Expand Down Expand Up @@ -115,20 +112,19 @@ def on_failure_step(
timeout: str = "",
retries: int = 0,
rate_limits: list[RateLimit] | None = None,
) -> Callable[[Callable[P, R]], Callable[P, R]]:
def inner(func: Callable[P, R]) -> Callable[P, R]:
) -> Callable[[WorkflowStepProtocol], WorkflowStepProtocol]:
def inner(func: WorkflowStepProtocol) -> WorkflowStepProtocol:
limits = None
if rate_limits:
limits = [
CreateStepRateLimit(key=rate_limit.key, units=rate_limit.units)
for rate_limit in rate_limits or []
]

## TODO: Use Protocol here to help with MyPy errors
func._on_failure_step_name = name.lower() or str(func.__name__).lower() # type: ignore[attr-defined]
func._on_failure_step_timeout = timeout # type: ignore[attr-defined]
func._on_failure_step_retries = retries # type: ignore[attr-defined]
func._on_failure_step_rate_limits = limits # type: ignore[attr-defined]
func._on_failure_step_name = name.lower() or str(func.__name__).lower()
func._on_failure_step_timeout = timeout
func._on_failure_step_retries = retries
func._on_failure_step_rate_limits = limits
return func

return inner
Expand All @@ -138,12 +134,11 @@ def concurrency(
name: str = "",
max_runs: int = 1,
limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.CANCEL_IN_PROGRESS,
) -> Callable[[Callable[P, R]], Callable[P, R]]:
def inner(func: Callable[P, R]) -> Callable[P, R]:
## TODO: Use Protocol here to help with MyPy errors
func._concurrency_fn_name = name.lower() or str(func.__name__).lower() # type: ignore[attr-defined]
func._concurrency_max_runs = max_runs # type: ignore[attr-defined]
func._concurrency_limit_strategy = limit_strategy # type: ignore[attr-defined]
) -> Callable[[WorkflowStepProtocol], WorkflowStepProtocol]:
def inner(func: WorkflowStepProtocol) -> WorkflowStepProtocol:
func._concurrency_fn_name = name.lower() or str(func.__name__).lower()
func._concurrency_max_runs = max_runs
func._concurrency_limit_strategy = limit_strategy

return func

Expand Down
8 changes: 6 additions & 2 deletions hatchet_sdk/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
_step_retries: int | None
_step_rate_limits: list[str] | None
_step_desired_worker_labels: dict[str, str]

_concurrency_fn_name: str
_concurrency_max_runs: int | None
_concurrency_limit_strategy: str | None

_on_failure_step_name: str
_on_failure_step_timeout: str | None
_on_failure_step_retries: str | None
_on_failure_step_rate_limits: list[str]
_on_failure_step_retries: int
_on_failure_step_rate_limits: list[str] | None


StepsType = list[tuple[str, WorkflowStepProtocol]]
Expand Down

0 comments on commit c61505e

Please sign in to comment.