Skip to content

Commit

Permalink
Deprecate futures_executor field
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Jan 6, 2025
1 parent c09fc8b commit 5c77ab5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `BaseVectorStoreDriver.query_vector` for querying vector stores with vectors.

### Fixed

- Occasional crash during `FuturesExecutorMixin` cleanup.

### Deprecated

- `FuturesExecutorMixin.futures_executor`. Use `FuturesExecutorMixin.create_futures_executor` instead.

## [1.1.1] - 2025-01-03

### Fixed
Expand Down
26 changes: 24 additions & 2 deletions griptape/mixins/futures_executor_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from abc import ABC
from concurrent import futures
from typing import Callable
Expand All @@ -13,6 +14,27 @@ class FuturesExecutorMixin(ABC):
default=Factory(lambda: lambda: futures.ThreadPoolExecutor()),
)

futures_executor: futures.Executor = field(
default=Factory(lambda self: self.create_futures_executor(), takes_self=True)
_futures_executor: futures.Executor = field(
default=Factory(
lambda self: self.create_futures_executor(),
takes_self=True,
),
alias="futures_executor",
)

@property
def futures_executor(self) -> futures.Executor:
self.__raise_deprecation_warning()
return self._futures_executor

@futures_executor.setter
def futures_executor(self, value: futures.Executor) -> None:
self.__raise_deprecation_warning()
self._futures_executor = value

def __raise_deprecation_warning(self) -> None:
warnings.warn(
"`FuturesExecutorMixin.futures_executor` is deprecated and will be removed in a future release. Use `FuturesExecutorMixin.create_futures_executor` instead.",
DeprecationWarning,
stacklevel=2,
)
8 changes: 8 additions & 0 deletions tests/unit/mixins/test_futures_executor_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from concurrent import futures

import pytest

from tests.mocks.mock_futures_executor import MockFuturesExecutor


Expand All @@ -8,3 +10,9 @@ def test_futures_executor(self):
executor = futures.ThreadPoolExecutor()

assert MockFuturesExecutor(create_futures_executor=lambda: executor).futures_executor == executor

def test_deprecated_futures_executor(self):
mock_executor = MockFuturesExecutor()
with pytest.warns(DeprecationWarning):
assert mock_executor.futures_executor
mock_executor.futures_executor = futures.ThreadPoolExecutor()

0 comments on commit 5c77ab5

Please sign in to comment.