Skip to content

Commit 9170eef

Browse files
committed
Fix pylint false positives for ThreadPoolExecutor and Future
1 parent 27508ed commit 9170eef

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

instrumentation/opentelemetry-instrumentation-asyncio/tests/test_asyncio_run_coroutine_threadsafe.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# limitations under the License.
1414
import asyncio
1515
import threading
16-
from concurrent.futures import ( # pylint: disable=no-name-in-module; TODO #4199
17-
ThreadPoolExecutor,
18-
)
16+
# from concurrent.futures import ( # pylint: disable=no-name-in-module; TODO #4199
17+
# ThreadPoolExecutor,
18+
# )
19+
import concurrent.futures
1920
from unittest.mock import patch
2021

2122
# pylint: disable=no-name-in-module
@@ -35,7 +36,7 @@ def setUp(self):
3536
super().setUp()
3637
AsyncioInstrumentor().instrument()
3738
self.loop = asyncio.new_event_loop()
38-
self.executor = ThreadPoolExecutor(max_workers=1)
39+
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
3940
self.loop.set_default_executor(self.executor)
4041
self.thread = threading.Thread(target=self.loop.run_forever)
4142
self.thread.start()

instrumentation/opentelemetry-instrumentation-threading/tests/test_threading.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
# limitations under the License.
1414

1515
import threading
16-
from concurrent.futures import ( # pylint: disable=no-name-in-module; TODO #4199
17-
ThreadPoolExecutor,
18-
)
16+
# from concurrent.futures import ( # pylint: disable=no-name-in-module; TODO #4199
17+
# ThreadPoolExecutor,
18+
# )
19+
20+
import concurrent.futures
1921
from typing import List
2022
from unittest.mock import MagicMock, patch
2123

@@ -63,7 +65,7 @@ def test_trace_context_propagation_in_thread_pool_with_multiple_workers(
6365
self,
6466
):
6567
max_workers = 10
66-
executor = ThreadPoolExecutor(max_workers=max_workers)
68+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=max_workers)
6769

6870
expected_span_contexts: List[trace.SpanContext] = []
6971
futures_list = []
@@ -83,7 +85,7 @@ def test_trace_context_propagation_in_thread_pool_with_multiple_workers(
8385

8486
def test_trace_context_propagation_in_thread_pool_with_single_worker(self):
8587
max_workers = 1
86-
with ThreadPoolExecutor(max_workers=max_workers) as executor:
88+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
8789
# test propagation of the same trace context across multiple tasks
8890
with self._tracer.start_as_current_span("task") as task_span:
8991
expected_task_context = task_span.get_span_context()
@@ -271,7 +273,7 @@ def test_threading_with_valid_context_token(self, mock_detach: MagicMock):
271273
def test_thread_pool_with_none_context_token(self, mock_detach: MagicMock):
272274
with (
273275
self.get_root_span(),
274-
ThreadPoolExecutor(max_workers=1) as executor,
276+
concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor,
275277
):
276278
future = executor.submit(self.get_current_span_context_for_test)
277279
future.result()
@@ -289,7 +291,7 @@ def test_thread_pool_with_none_context_token(self, mock_detach: MagicMock):
289291
def test_threadpool_with_valid_context_token(self, mock_detach: MagicMock):
290292
with (
291293
self.get_root_span(),
292-
ThreadPoolExecutor(max_workers=1) as executor,
294+
concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor,
293295
):
294296
future = executor.submit(self.get_current_span_context_for_test)
295297
future.result()

test_pylint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from concurrent.futures import ThreadPoolExecutor

util/opentelemetry-util-genai/src/opentelemetry/util/genai/_upload/completion_hook.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import posixpath
2323
import threading
2424
from collections import OrderedDict
25-
from concurrent.futures import ( # pylint: disable=no-name-in-module; TODO #4199
26-
Future,
27-
ThreadPoolExecutor,
28-
)
25+
# from concurrent.futures import ( # pylint: disable=no-name-in-module; TODO #4199
26+
# Future,
27+
# ThreadPoolExecutor,
28+
# )
29+
import concurrent.futures
2930
from contextlib import ExitStack
3031
from dataclasses import asdict, dataclass
3132
from functools import partial
@@ -159,13 +160,13 @@ def __init__(
159160

160161
# Use a ThreadPoolExecutor for its queueing and thread management. The semaphore
161162
# limits the number of queued tasks. If the queue is full, data will be dropped.
162-
self._executor = ThreadPoolExecutor(
163+
self._executor = concurrent.futures.ThreadPoolExecutor(
163164
max_workers=min(self._max_queue_size, 64)
164165
)
165166
self._semaphore = threading.BoundedSemaphore(self._max_queue_size)
166167

167168
def _submit_all(self, upload_data: UploadData) -> None:
168-
def done(future: Future[None]) -> None:
169+
def done(future: concurrent.futures.Future[None]) -> None:
169170
try:
170171
future.result()
171172
except Exception: # pylint: disable=broad-except

0 commit comments

Comments
 (0)