Skip to content

Commit

Permalink
Merge branch 'main' into eager-tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Dec 27, 2024
2 parents 8493e59 + 64173cd commit 6733910
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 36 deletions.
27 changes: 26 additions & 1 deletion Doc/deprecations/pending-removal-in-3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,35 @@ Pending removal in Python 3.16
* :mod:`asyncio`:

* :func:`!asyncio.iscoroutinefunction` is deprecated
and will be removed in Python 3.16,
and will be removed in Python 3.16;
use :func:`inspect.iscoroutinefunction` instead.
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.)

* :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16.
In particular, the following classes and functions are deprecated:

* :class:`asyncio.AbstractEventLoopPolicy`
* :class:`asyncio.DefaultEventLoopPolicy`
* :class:`asyncio.WindowsSelectorEventLoopPolicy`
* :class:`asyncio.WindowsProactorEventLoopPolicy`
* :func:`asyncio.get_event_loop_policy`
* :func:`asyncio.set_event_loop_policy`
* :func:`asyncio.set_event_loop`

Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
*loop_factory* to use the desired event loop implementation.

For example, to use :class:`asyncio.SelectorEventLoop` on Windows::

import asyncio

async def main():
...

asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)

(Contributed by Kumar Aditya in :gh:`127949`.)

* :mod:`builtins`:

* Bitwise inversion on boolean types, ``~True`` or ``~False``
Expand Down
16 changes: 11 additions & 5 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ an event loop:
.. versionchanged:: 3.14
Raises a :exc:`RuntimeError` if there is no current event loop.

.. note::

The :mod:`!asyncio` policy system is deprecated and will be removed
in Python 3.16; from there on, this function will always return the
running event loop.


.. function:: set_event_loop(loop)

Set *loop* as the current event loop for the current OS thread.
Expand Down Expand Up @@ -1781,12 +1788,11 @@ By default asyncio is configured to use :class:`EventLoop`.
import asyncio
import selectors

class MyPolicy(asyncio.DefaultEventLoopPolicy):
def new_event_loop(self):
selector = selectors.SelectSelector()
return asyncio.SelectorEventLoop(selector)
async def main():
...

asyncio.set_event_loop_policy(MyPolicy())
loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector())
asyncio.run(main(), loop_factory=loop_factory)


.. availability:: Unix, Windows.
Expand Down
6 changes: 6 additions & 0 deletions Doc/library/asyncio-runner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Running an asyncio Program

Added *eager_tasks* parameter.

.. note::

The :mod:`!asyncio` policy system is deprecated and will be removed
in Python 3.16; from there on, an explicit *loop_factory* is needed
to configure the event loop.


Runner context manager
======================
Expand Down
41 changes: 26 additions & 15 deletions Lib/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def is_server_error(self):
CONTINUE = 100, 'Continue', 'Request received, please continue'
SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
'Switching to new protocol; obey Upgrade header')
PROCESSING = 102, 'Processing'
EARLY_HINTS = 103, 'Early Hints'
PROCESSING = 102, 'Processing', 'Server is processing the request'
EARLY_HINTS = (103, 'Early Hints',
'Headers sent to prepare for the response')

# success
OK = 200, 'OK', 'Request fulfilled, document follows'
Expand All @@ -67,9 +68,11 @@ def is_server_error(self):
NO_CONTENT = 204, 'No Content', 'Request fulfilled, nothing follows'
RESET_CONTENT = 205, 'Reset Content', 'Clear input form for further input'
PARTIAL_CONTENT = 206, 'Partial Content', 'Partial content follows'
MULTI_STATUS = 207, 'Multi-Status'
ALREADY_REPORTED = 208, 'Already Reported'
IM_USED = 226, 'IM Used'
MULTI_STATUS = (207, 'Multi-Status',
'Response contains multiple statuses in the body')
ALREADY_REPORTED = (208, 'Already Reported',
'Operation has already been reported')
IM_USED = 226, 'IM Used', 'Request completed using instance manipulations'

# redirection
MULTIPLE_CHOICES = (300, 'Multiple Choices',
Expand Down Expand Up @@ -128,15 +131,19 @@ def is_server_error(self):
EXPECTATION_FAILED = (417, 'Expectation Failed',
'Expect condition could not be satisfied')
IM_A_TEAPOT = (418, 'I\'m a Teapot',
'Server refuses to brew coffee because it is a teapot.')
'Server refuses to brew coffee because it is a teapot')
MISDIRECTED_REQUEST = (421, 'Misdirected Request',
'Server is not able to produce a response')
UNPROCESSABLE_CONTENT = 422, 'Unprocessable Content'
UNPROCESSABLE_CONTENT = (422, 'Unprocessable Content',
'Server is not able to process the contained instructions')
UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT
LOCKED = 423, 'Locked'
FAILED_DEPENDENCY = 424, 'Failed Dependency'
TOO_EARLY = 425, 'Too Early'
UPGRADE_REQUIRED = 426, 'Upgrade Required'
LOCKED = 423, 'Locked', 'Resource of a method is locked'
FAILED_DEPENDENCY = (424, 'Failed Dependency',
'Dependent action of the request failed')
TOO_EARLY = (425, 'Too Early',
'Server refuses to process a request that might be replayed')
UPGRADE_REQUIRED = (426, 'Upgrade Required',
'Server refuses to perform the request using the current protocol')
PRECONDITION_REQUIRED = (428, 'Precondition Required',
'The origin server requires the request to be conditional')
TOO_MANY_REQUESTS = (429, 'Too Many Requests',
Expand Down Expand Up @@ -164,10 +171,14 @@ def is_server_error(self):
'The gateway server did not receive a timely response')
HTTP_VERSION_NOT_SUPPORTED = (505, 'HTTP Version Not Supported',
'Cannot fulfill request')
VARIANT_ALSO_NEGOTIATES = 506, 'Variant Also Negotiates'
INSUFFICIENT_STORAGE = 507, 'Insufficient Storage'
LOOP_DETECTED = 508, 'Loop Detected'
NOT_EXTENDED = 510, 'Not Extended'
VARIANT_ALSO_NEGOTIATES = (506, 'Variant Also Negotiates',
'Server has an internal configuration error')
INSUFFICIENT_STORAGE = (507, 'Insufficient Storage',
'Server is not able to store the representation')
LOOP_DETECTED = (508, 'Loop Detected',
'Server encountered an infinite loop while processing a request')
NOT_EXTENDED = (510, 'Not Extended',
'Request does not meet the resource access policy')
NETWORK_AUTHENTICATION_REQUIRED = (511,
'Network Authentication Required',
'The client needs to authenticate to gain network access')
Expand Down
41 changes: 26 additions & 15 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,9 @@ def is_server_error(self):
CONTINUE = 100, 'Continue', 'Request received, please continue'
SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
'Switching to new protocol; obey Upgrade header')
PROCESSING = 102, 'Processing'
EARLY_HINTS = 103, 'Early Hints'
PROCESSING = 102, 'Processing', 'Server is processing the request'
EARLY_HINTS = (103, 'Early Hints',
'Headers sent to prepare for the response')
# success
OK = 200, 'OK', 'Request fulfilled, document follows'
CREATED = 201, 'Created', 'Document created, URL follows'
Expand All @@ -606,9 +607,11 @@ def is_server_error(self):
NO_CONTENT = 204, 'No Content', 'Request fulfilled, nothing follows'
RESET_CONTENT = 205, 'Reset Content', 'Clear input form for further input'
PARTIAL_CONTENT = 206, 'Partial Content', 'Partial content follows'
MULTI_STATUS = 207, 'Multi-Status'
ALREADY_REPORTED = 208, 'Already Reported'
IM_USED = 226, 'IM Used'
MULTI_STATUS = (207, 'Multi-Status',
'Response contains multiple statuses in the body')
ALREADY_REPORTED = (208, 'Already Reported',
'Operation has already been reported')
IM_USED = 226, 'IM Used', 'Request completed using instance manipulations'
# redirection
MULTIPLE_CHOICES = (300, 'Multiple Choices',
'Object has several resources -- see URI list')
Expand Down Expand Up @@ -665,15 +668,19 @@ def is_server_error(self):
EXPECTATION_FAILED = (417, 'Expectation Failed',
'Expect condition could not be satisfied')
IM_A_TEAPOT = (418, 'I\'m a Teapot',
'Server refuses to brew coffee because it is a teapot.')
'Server refuses to brew coffee because it is a teapot')
MISDIRECTED_REQUEST = (421, 'Misdirected Request',
'Server is not able to produce a response')
UNPROCESSABLE_CONTENT = 422, 'Unprocessable Content'
UNPROCESSABLE_CONTENT = (422, 'Unprocessable Content',
'Server is not able to process the contained instructions')
UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT
LOCKED = 423, 'Locked'
FAILED_DEPENDENCY = 424, 'Failed Dependency'
TOO_EARLY = 425, 'Too Early'
UPGRADE_REQUIRED = 426, 'Upgrade Required'
LOCKED = 423, 'Locked', 'Resource of a method is locked'
FAILED_DEPENDENCY = (424, 'Failed Dependency',
'Dependent action of the request failed')
TOO_EARLY = (425, 'Too Early',
'Server refuses to process a request that might be replayed')
UPGRADE_REQUIRED = (426, 'Upgrade Required',
'Server refuses to perform the request using the current protocol')
PRECONDITION_REQUIRED = (428, 'Precondition Required',
'The origin server requires the request to be conditional')
TOO_MANY_REQUESTS = (429, 'Too Many Requests',
Expand All @@ -700,10 +707,14 @@ def is_server_error(self):
'The gateway server did not receive a timely response')
HTTP_VERSION_NOT_SUPPORTED = (505, 'HTTP Version Not Supported',
'Cannot fulfill request')
VARIANT_ALSO_NEGOTIATES = 506, 'Variant Also Negotiates'
INSUFFICIENT_STORAGE = 507, 'Insufficient Storage'
LOOP_DETECTED = 508, 'Loop Detected'
NOT_EXTENDED = 510, 'Not Extended'
VARIANT_ALSO_NEGOTIATES = (506, 'Variant Also Negotiates',
'Server has an internal configuration error')
INSUFFICIENT_STORAGE = (507, 'Insufficient Storage',
'Server is not able to store the representation')
LOOP_DETECTED = (508, 'Loop Detected',
'Server encountered an infinite loop while processing a request')
NOT_EXTENDED = (510, 'Not Extended',
'Request does not meet the resource access policy')
NETWORK_AUTHENTICATION_REQUIRED = (511,
'Network Authentication Required',
'The client needs to authenticate to gain network access')
Expand Down

0 comments on commit 6733910

Please sign in to comment.