Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let typing be compatible with python 3.8 #13288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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