]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43234: Prohibit non-ThreadPoolExecutor in loop.set_default_executor (GH-24540)
authorIllia Volochii <illia.volochii@gmail.com>
Thu, 1 Jul 2021 14:46:49 +0000 (17:46 +0300)
committerGitHub <noreply@github.com>
Thu, 1 Jul 2021 14:46:49 +0000 (17:46 +0300)
Doc/library/asyncio-eventloop.rst
Doc/whatsnew/3.11.rst
Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_base_events.py
Misc/NEWS.d/next/Library/2021-02-15-22-14-31.bpo-43234.F-vKAT.rst [new file with mode: 0644]

index 83ab7360a9b6e2efdb8ee46dbfafa2eaa04398c5..f0f6ae6d98ff99f62c78c8e25bcdf0c4892ab88f 100644 (file)
@@ -1132,16 +1132,12 @@ Executing code in thread or process pools
 .. method:: loop.set_default_executor(executor)
 
    Set *executor* as the default executor used by :meth:`run_in_executor`.
-   *executor* should be an instance of
+   *executor* must be an instance of
    :class:`~concurrent.futures.ThreadPoolExecutor`.
 
-   .. deprecated:: 3.8
-      Using an executor that is not an instance of
-      :class:`~concurrent.futures.ThreadPoolExecutor` is deprecated and
-      will trigger an error in Python 3.9.
-
-   *executor* must be an instance of
-   :class:`concurrent.futures.ThreadPoolExecutor`.
+   .. versionchanged:: 3.11
+      *executor* must be an instance of
+      :class:`~concurrent.futures.ThreadPoolExecutor`.
 
 
 Error Handling API
index 94d8bef4d521b0b9bff9a766110e176c21d01194..5b51273ed6b9a2b6814fb908ac40910545f6448a 100644 (file)
@@ -188,6 +188,15 @@ This section lists previously described changes and other bugfixes
 that may require changes to your code.
 
 
+Changes in the Python API
+-------------------------
+
+* Prohibited passing non-:class:`concurrent.futures.ThreadPoolExecutor`
+  executors to :meth:`loop.set_default_executor` following a deprecation in
+  Python 3.8.
+  (Contributed by Illia Volochii in :issue:`43234`.)
+
+
 C API Changes
 =============
 
index f789635e0f893a3ec86346393b0b939557bfd963..74d5670bf74edb603ed4be9f39246865f2d9726b 100644 (file)
@@ -814,11 +814,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 
     def set_default_executor(self, executor):
         if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
-            warnings.warn(
-                'Using the default executor that is not an instance of '
-                'ThreadPoolExecutor is deprecated and will be prohibited '
-                'in Python 3.9',
-                DeprecationWarning, 2)
+            raise TypeError('executor must be ThreadPoolExecutor instance')
         self._default_executor = executor
 
     def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
index 47a9fb98001b4d2ab959324a2e467c9cc8581ca2..adc7bd42c1508d0285fbba7b0359acab994df224 100644 (file)
@@ -224,14 +224,14 @@ class BaseEventLoopTests(test_utils.TestCase):
         self.loop.set_default_executor(executor)
         self.assertIs(executor, self.loop._default_executor)
 
-    def test_set_default_executor_deprecation_warnings(self):
+    def test_set_default_executor_error(self):
         executor = mock.Mock()
 
-        with self.assertWarns(DeprecationWarning):
+        msg = 'executor must be ThreadPoolExecutor instance'
+        with self.assertRaisesRegex(TypeError, msg):
             self.loop.set_default_executor(executor)
 
-        # Avoid cleaning up the executor mock
-        self.loop._default_executor = None
+        self.assertIsNone(self.loop._default_executor)
 
     def test_call_soon(self):
         def cb():
diff --git a/Misc/NEWS.d/next/Library/2021-02-15-22-14-31.bpo-43234.F-vKAT.rst b/Misc/NEWS.d/next/Library/2021-02-15-22-14-31.bpo-43234.F-vKAT.rst
new file mode 100644 (file)
index 0000000..7f195cc
--- /dev/null
@@ -0,0 +1,3 @@
+Prohibit passing non-:class:`concurrent.futures.ThreadPoolExecutor`
+executors to :meth:`loop.set_default_executor` following a deprecation in
+Python 3.8. Patch by Illia Volochii.