]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42413: Replace `concurrent.futures.TimeoutError` and `asyncio.TimeoutError` with...
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Sun, 19 Dec 2021 11:22:40 +0000 (16:52 +0530)
committerGitHub <noreply@github.com>
Sun, 19 Dec 2021 11:22:40 +0000 (13:22 +0200)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Doc/library/asyncio-api-index.rst
Doc/library/asyncio-exceptions.rst
Doc/library/asyncio-task.rst
Doc/library/concurrent.futures.rst
Lib/asyncio/exceptions.py
Lib/concurrent/futures/_base.py
Misc/NEWS.d/next/Library/2020-11-26-10-23-46.bpo-42413.HFikOl.rst [new file with mode: 0644]

index f558724d4a3ff658bbd7bd7f254a52552a08ef0c..8bc7943a7173919a0355ddb2cbc475dca1d51da0 100644 (file)
@@ -203,11 +203,6 @@ Exceptions
     :class: full-width-table
 
 
-    * - :exc:`asyncio.TimeoutError`
-      - Raised on timeout by functions like :func:`wait_for`.
-        Keep in mind that ``asyncio.TimeoutError`` is **unrelated**
-        to the built-in :exc:`TimeoutError` exception.
-
     * - :exc:`asyncio.CancelledError`
       - Raised when a Task is cancelled. See also :meth:`Task.cancel`.
 
index 7166d5c4bd88f9b155b6665ba0b512c28863b526..9250f01b8a0895312507865c94445f92f06b242f 100644 (file)
@@ -13,11 +13,12 @@ Exceptions
 
 .. exception:: TimeoutError
 
-   The operation has exceeded the given deadline.
+   A deprecated alias of :exc:`TimeoutError`,
+   raised when the operation has exceeded the given deadline.
 
-   .. important::
-      This exception is different from the builtin :exc:`TimeoutError`
-      exception.
+   .. versionchanged:: 3.11
+
+      This class was made an alias of :exc:`TimeoutError`.
 
 
 .. exception:: CancelledError
index bfc983e304bccf42c1ca1e828736ca579357d113..cbc42ac26e48c89d2f087954b3074d750db87f96 100644 (file)
@@ -490,7 +490,7 @@ Timeouts
    completes.
 
    If a timeout occurs, it cancels the task and raises
-   :exc:`asyncio.TimeoutError`.
+   :exc:`TimeoutError`.
 
    To avoid the task :meth:`cancellation <Task.cancel>`,
    wrap it in :func:`shield`.
@@ -520,7 +520,7 @@ Timeouts
            # Wait for at most 1 second
            try:
                await asyncio.wait_for(eternity(), timeout=1.0)
-           except asyncio.TimeoutError:
+           except TimeoutError:
                print('timeout!')
 
        asyncio.run(main())
@@ -532,7 +532,7 @@ Timeouts
    .. versionchanged:: 3.7
       When *aw* is cancelled due to a timeout, ``wait_for`` waits
       for *aw* to be cancelled.  Previously, it raised
-      :exc:`asyncio.TimeoutError` immediately.
+      :exc:`TimeoutError` immediately.
 
    .. deprecated-removed:: 3.8 3.10
       The ``loop`` parameter.  This function has been implicitly getting the
@@ -561,7 +561,7 @@ Waiting Primitives
    *timeout* (a float or int), if specified, can be used to control
    the maximum number of seconds to wait before returning.
 
-   Note that this function does not raise :exc:`asyncio.TimeoutError`.
+   Note that this function does not raise :exc:`TimeoutError`.
    Futures or Tasks that aren't done when the timeout occurs are simply
    returned in the second set.
 
@@ -649,7 +649,7 @@ Waiting Primitives
    Each coroutine returned can be awaited to get the earliest next
    result from the iterable of the remaining awaitables.
 
-   Raises :exc:`asyncio.TimeoutError` if the timeout occurs before
+   Raises :exc:`TimeoutError` if the timeout occurs before
    all Futures are done.
 
    .. deprecated-removed:: 3.8 3.10
@@ -762,7 +762,7 @@ Scheduling From Other Threads
 
      try:
          result = future.result(timeout)
-     except concurrent.futures.TimeoutError:
+     except TimeoutError:
          print('The coroutine took too long, cancelling the task...')
          future.cancel()
      except Exception as exc:
index b4213b451157e39a80a9da87fa5b877b5c43ae89..c9f6aa1f2637cdeb0a9f8f11d1eb54adeeb1fcc6 100644 (file)
@@ -47,7 +47,7 @@ Executor Objects
        * *func* is executed asynchronously and several calls to
          *func* may be made concurrently.
 
-       The returned iterator raises a :exc:`concurrent.futures.TimeoutError`
+       The returned iterator raises a :exc:`TimeoutError`
        if :meth:`~iterator.__next__` is called and the result isn't available
        after *timeout* seconds from the original call to :meth:`Executor.map`.
        *timeout* can be an int or a float.  If *timeout* is not specified or
@@ -352,7 +352,7 @@ The :class:`Future` class encapsulates the asynchronous execution of a callable.
        Return the value returned by the call. If the call hasn't yet completed
        then this method will wait up to *timeout* seconds.  If the call hasn't
        completed in *timeout* seconds, then a
-       :exc:`concurrent.futures.TimeoutError` will be raised. *timeout* can be
+       :exc:`TimeoutError` will be raised. *timeout* can be
        an int or float.  If *timeout* is not specified or ``None``, there is no
        limit to the wait time.
 
@@ -366,7 +366,7 @@ The :class:`Future` class encapsulates the asynchronous execution of a callable.
        Return the exception raised by the call.  If the call hasn't yet
        completed then this method will wait up to *timeout* seconds.  If the
        call hasn't completed in *timeout* seconds, then a
-       :exc:`concurrent.futures.TimeoutError` will be raised.  *timeout* can be
+       :exc:`TimeoutError` will be raised.  *timeout* can be
        an int or float.  If *timeout* is not specified or ``None``, there is no
        limit to the wait time.
 
@@ -482,7 +482,7 @@ Module Functions
    they complete (finished or cancelled futures). Any futures given by *fs* that
    are duplicated will be returned once. Any futures that completed before
    :func:`as_completed` is called will be yielded first.  The returned iterator
-   raises a :exc:`concurrent.futures.TimeoutError` if :meth:`~iterator.__next__`
+   raises a :exc:`TimeoutError` if :meth:`~iterator.__next__`
    is called and the result isn't available after *timeout* seconds from the
    original call to :func:`as_completed`.  *timeout* can be an int or float. If
    *timeout* is not specified or ``None``, there is no limit to the wait time.
@@ -506,7 +506,13 @@ Exception classes
 
 .. exception:: TimeoutError
 
-   Raised when a future operation exceeds the given timeout.
+   A deprecated alias of :exc:`TimeoutError`,
+   raised when a future operation exceeds the given timeout.
+
+   .. versionchanged:: 3.11
+
+      This class was made an alias of :exc:`TimeoutError`.
+
 
 .. exception:: BrokenExecutor
 
index f07e4486577381616e7e2f7f05747ed7374316a1..c764c9ffcfc199b69a37eb9eea640236a0e49154 100644 (file)
@@ -10,8 +10,7 @@ class CancelledError(BaseException):
     """The Future or Task was cancelled."""
 
 
-class TimeoutError(Exception):
-    """The operation exceeded the given deadline."""
+TimeoutError = TimeoutError  # make local alias for the standard exception
 
 
 class InvalidStateError(Exception):
index 6095026cb278b9f3158505886416f094041c258d..b0337399e5f25ead5d1506ba43fa99567f0f7e92 100644 (file)
@@ -50,9 +50,7 @@ class CancelledError(Error):
     """The Future was cancelled."""
     pass
 
-class TimeoutError(Error):
-    """The operation exceeded the given deadline."""
-    pass
+TimeoutError = TimeoutError  # make local alias for the standard exception
 
 class InvalidStateError(Error):
     """The operation is not allowed in this state."""
diff --git a/Misc/NEWS.d/next/Library/2020-11-26-10-23-46.bpo-42413.HFikOl.rst b/Misc/NEWS.d/next/Library/2020-11-26-10-23-46.bpo-42413.HFikOl.rst
new file mode 100644 (file)
index 0000000..85b7fe2
--- /dev/null
@@ -0,0 +1,2 @@
+Replace ``concurrent.futures.TimeoutError`` and ``asyncio.TimeoutError``
+with builtin :exc:`TimeoutError`, keep these names as deprecated aliases.