Skip to content

Commit

Permalink
let typing be compatible with python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dlee992 committed May 8, 2024
1 parent cb84f4a commit 01a26c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/integrations/prefect-dask/prefect_dask/task_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def count_to(highest_number):

import inspect
from contextlib import AsyncExitStack
from typing import Awaitable, Callable, Dict, Optional, Union
from typing import Callable, Dict, Optional, Union
from uuid import UUID

import distributed
Expand All @@ -82,7 +82,7 @@ def count_to(highest_number):
from prefect.context import FlowRunContext
from prefect.futures import PrefectFuture
from prefect.states import exception_to_crashed_state
from prefect.task_runners import BaseTaskRunner, R, TaskConcurrencyType
from prefect.task_runners import BaseTaskRunner, CallableGeneric, R, TaskConcurrencyType
from prefect.utilities.collections import visit_collection
from prefect.utilities.importtools import from_qualified_name, to_qualified_name

Expand Down Expand Up @@ -254,7 +254,7 @@ def __eq__(self, other: object) -> bool:
async def submit(
self,
key: UUID,
call: Callable[..., Awaitable[State[R]]],
call: CallableGeneric[R],
) -> None:
if not self._started:
raise RuntimeError(
Expand Down
6 changes: 3 additions & 3 deletions src/integrations/prefect-ray/prefect_ray/task_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def count_to(highest_number):
"""

from contextlib import AsyncExitStack
from typing import Awaitable, Callable, Dict, Optional
from typing import Dict, Optional
from uuid import UUID

import anyio
Expand All @@ -81,7 +81,7 @@ def count_to(highest_number):

from prefect.futures import PrefectFuture
from prefect.states import State, exception_to_crashed_state
from prefect.task_runners import BaseTaskRunner, R, TaskConcurrencyType
from prefect.task_runners import BaseTaskRunner, CallableGeneric, R, TaskConcurrencyType
from prefect.utilities.asyncutils import sync_compatible
from prefect.utilities.collections import visit_collection
from prefect_ray.context import RemoteOptionsContext
Expand Down Expand Up @@ -153,7 +153,7 @@ def concurrency_type(self) -> TaskConcurrencyType:
async def submit(
self,
key: UUID,
call: Callable[..., Awaitable[State[R]]],
call: CallableGeneric[R],
) -> None:
if not self._started:
raise RuntimeError(
Expand Down
9 changes: 9 additions & 0 deletions src/prefect/task_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
For usage details, see the [Task Runners](/concepts/task-runners/) documentation.
"""

import abc
from contextlib import AsyncExitStack, asynccontextmanager
from typing import (
Expand All @@ -60,6 +61,7 @@
Awaitable,
Callable,
Dict,
Generic,
Optional,
Set,
TypeVar,
Expand All @@ -80,6 +82,13 @@

T = TypeVar("T", bound="BaseTaskRunner")
R = TypeVar("R")
StateR = TypeVar("StateR", bound=State[R])


class CallableGeneric(Generic[R]):
# create this class to be compatible with python 3.8
def __call__(self, *args, **kwargs) -> Awaitable[StateR]:
pass


class TaskConcurrencyType(AutoEnum):
Expand Down

0 comments on commit 01a26c6

Please sign in to comment.