Skip to content

Commit

Permalink
feat: remove py38 work-arounds
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Oct 8, 2024
1 parent 173606d commit 70f5ace
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/darker/concurrency.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
"""Concurrency helpers for enhancing the performance of Darker"""

import sys
from concurrent.futures import Executor, Future, ProcessPoolExecutor
from typing import Any, Callable, Generic, TypeVar, cast
from typing import Any, Callable, TypeVar

T = TypeVar("T") # pylint: disable=invalid-name

if sys.version_info < (3, 9):

class FutureType(Generic[T]):
"""For Python <3.9 compatibility"""

def set_exception(self, exc_info: BaseException) -> None:
"Dummy method for typing"

def set_result(self, result: Any) -> None:
"Dummy method for typing"

else:
FutureType = Future


class DummyExecutor(Executor):
"""Dummy synchronous executor to use with ``--workers=1``
Expand All @@ -31,7 +16,7 @@ class DummyExecutor(Executor):
# pylint: disable=arguments-differ,unsubscriptable-object,broad-except
def submit( # type: ignore[override]
self, fn: Callable[..., T], *args: Any, **kwargs: Any
) -> FutureType[T]:
) -> Future[T]:
"""Submits "a callable to be executed with the given arguments.
Executes the callable immediately as ``fn(*args, **kwargs)`` and returns a
Expand All @@ -43,7 +28,7 @@ def submit( # type: ignore[override]
:return: A `Future` representing the given call
"""
future = cast(FutureType[T], Future())
future = Future()
try:
result = fn(*args, **kwargs)
except BaseException as exc_info: # noqa: B036
Expand Down

0 comments on commit 70f5ace

Please sign in to comment.