Skip to content

Commit f69394e

Browse files
committed
Merge branch 'main' into gh-127794
2 parents 079dda7 + b2ac70a commit f69394e

File tree

103 files changed

+1691
-1048
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1691
-1048
lines changed

Doc/c-api/object.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ Object Protocol
111111
.. note::
112112
113113
Exceptions that occur when this calls :meth:`~object.__getattr__` and
114-
:meth:`~object.__getattribute__` methods are silently ignored.
114+
:meth:`~object.__getattribute__` methods aren't propagated,
115+
but instead given to :func:`sys.unraisablehook`.
115116
For proper error handling, use :c:func:`PyObject_HasAttrWithError`,
116117
:c:func:`PyObject_GetOptionalAttr` or :c:func:`PyObject_GetAttr` instead.
117118

Doc/c-api/typeobj.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
10231023
:c:macro:`Py_TPFLAGS_HAVE_GC` flag bit is clear in the subtype and the
10241024
:c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear` fields in the subtype exist and have
10251025
``NULL`` values.
1026+
10261027
.. XXX are most flag bits *really* inherited individually?
10271028
10281029
**Default:**

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,35 @@ Pending removal in Python 3.16
1919
* :mod:`asyncio`:
2020

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

26+
* :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16.
27+
In particular, the following classes and functions are deprecated:
28+
29+
* :class:`asyncio.AbstractEventLoopPolicy`
30+
* :class:`asyncio.DefaultEventLoopPolicy`
31+
* :class:`asyncio.WindowsSelectorEventLoopPolicy`
32+
* :class:`asyncio.WindowsProactorEventLoopPolicy`
33+
* :func:`asyncio.get_event_loop_policy`
34+
* :func:`asyncio.set_event_loop_policy`
35+
* :func:`asyncio.set_event_loop`
36+
37+
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
38+
*loop_factory* to use the desired event loop implementation.
39+
40+
For example, to use :class:`asyncio.SelectorEventLoop` on Windows::
41+
42+
import asyncio
43+
44+
async def main():
45+
...
46+
47+
asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
48+
49+
(Contributed by Kumar Aditya in :gh:`127949`.)
50+
2651
* :mod:`builtins`:
2752

2853
* Bitwise inversion on boolean types, ``~True`` or ``~False``

Doc/library/asyncio-eventloop.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,21 @@ an event loop:
6262
.. versionchanged:: 3.14
6363
Raises a :exc:`RuntimeError` if there is no current event loop.
6464

65+
.. note::
66+
67+
The :mod:`!asyncio` policy system is deprecated and will be removed
68+
in Python 3.16; from there on, this function will always return the
69+
running event loop.
70+
71+
6572
.. function:: set_event_loop(loop)
6673

6774
Set *loop* as the current event loop for the current OS thread.
6875

76+
.. deprecated:: next
77+
The :func:`set_event_loop` function is deprecated and will be removed
78+
in Python 3.16.
79+
6980
.. function:: new_event_loop()
7081

7182
Create and return a new event loop object.
@@ -1777,12 +1788,11 @@ By default asyncio is configured to use :class:`EventLoop`.
17771788
import asyncio
17781789
import selectors
17791790

1780-
class MyPolicy(asyncio.DefaultEventLoopPolicy):
1781-
def new_event_loop(self):
1782-
selector = selectors.SelectSelector()
1783-
return asyncio.SelectorEventLoop(selector)
1791+
async def main():
1792+
...
17841793

1785-
asyncio.set_event_loop_policy(MyPolicy())
1794+
loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector())
1795+
asyncio.run(main(), loop_factory=loop_factory)
17861796

17871797

17881798
.. availability:: Unix, Windows.

Doc/library/asyncio-policy.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
Policies
88
========
99

10+
.. warning::
11+
12+
Policies are deprecated and will be removed in Python 3.16.
13+
Users are encouraged to use the :func:`asyncio.run` function
14+
or the :class:`asyncio.Runner` with *loop_factory* to use
15+
the desired loop implementation.
16+
17+
1018
An event loop policy is a global object
1119
used to get and set the current :ref:`event loop <asyncio-event-loop>`,
1220
as well as create new event loops.
@@ -87,6 +95,10 @@ The abstract event loop policy base class is defined as follows:
8795

8896
This method should never return ``None``.
8997

98+
.. deprecated:: next
99+
The :class:`AbstractEventLoopPolicy` class is deprecated and
100+
will be removed in Python 3.16.
101+
90102

91103
.. _asyncio-policy-builtin:
92104

@@ -109,6 +121,10 @@ asyncio ships with the following built-in policies:
109121
The :meth:`get_event_loop` method of the default asyncio policy now
110122
raises a :exc:`RuntimeError` if there is no set event loop.
111123

124+
.. deprecated:: next
125+
The :class:`DefaultEventLoopPolicy` class is deprecated and
126+
will be removed in Python 3.16.
127+
112128

113129
.. class:: WindowsSelectorEventLoopPolicy
114130

@@ -117,6 +133,10 @@ asyncio ships with the following built-in policies:
117133

118134
.. availability:: Windows.
119135

136+
.. deprecated:: next
137+
The :class:`WindowsSelectorEventLoopPolicy` class is deprecated and
138+
will be removed in Python 3.16.
139+
120140

121141
.. class:: WindowsProactorEventLoopPolicy
122142

@@ -125,6 +145,10 @@ asyncio ships with the following built-in policies:
125145

126146
.. availability:: Windows.
127147

148+
.. deprecated:: next
149+
The :class:`WindowsProactorEventLoopPolicy` class is deprecated and
150+
will be removed in Python 3.16.
151+
128152

129153
.. _asyncio-custom-policies:
130154

Doc/library/asyncio-runner.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Running an asyncio Program
7676

7777
*coro* can be any awaitable object.
7878

79+
.. note::
80+
81+
The :mod:`!asyncio` policy system is deprecated and will be removed
82+
in Python 3.16; from there on, an explicit *loop_factory* is needed
83+
to configure the event loop.
84+
7985

8086
Runner context manager
8187
======================

Doc/library/asyncio-task.rst

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,14 +1067,59 @@ Scheduling From Other Threads
10671067
This function is meant to be called from a different OS thread
10681068
than the one where the event loop is running. Example::
10691069

1070-
# Create a coroutine
1071-
coro = asyncio.sleep(1, result=3)
1072-
1073-
# Submit the coroutine to a given loop
1074-
future = asyncio.run_coroutine_threadsafe(coro, loop)
1075-
1076-
# Wait for the result with an optional timeout argument
1077-
assert future.result(timeout) == 3
1070+
def in_thread(loop: asyncio.AbstractEventLoop) -> None:
1071+
# Run some blocking IO
1072+
pathlib.Path("example.txt").write_text("hello world", encoding="utf8")
1073+
1074+
# Create a coroutine
1075+
coro = asyncio.sleep(1, result=3)
1076+
1077+
# Submit the coroutine to a given loop
1078+
future = asyncio.run_coroutine_threadsafe(coro, loop)
1079+
1080+
# Wait for the result with an optional timeout argument
1081+
assert future.result(timeout=2) == 3
1082+
1083+
async def amain() -> None:
1084+
# Get the running loop
1085+
loop = asyncio.get_running_loop()
1086+
1087+
# Run something in a thread
1088+
await asyncio.to_thread(in_thread, loop)
1089+
1090+
It's also possible to run the other way around. Example::
1091+
1092+
@contextlib.contextmanager
1093+
def loop_in_thread() -> Generator[asyncio.AbstractEventLoop]:
1094+
loop_fut = concurrent.futures.Future[asyncio.AbstractEventLoop]()
1095+
stop_event = asyncio.Event()
1096+
1097+
async def main() -> None:
1098+
loop_fut.set_result(asyncio.get_running_loop())
1099+
await stop_event.wait()
1100+
1101+
with concurrent.futures.ThreadPoolExecutor(1) as tpe:
1102+
complete_fut = tpe.submit(asyncio.run, main())
1103+
for fut in concurrent.futures.as_completed((loop_fut, complete_fut)):
1104+
if fut is loop_fut:
1105+
loop = loop_fut.result()
1106+
try:
1107+
yield loop
1108+
finally:
1109+
loop.call_soon_threadsafe(stop_event.set)
1110+
else:
1111+
fut.result()
1112+
1113+
# Create a loop in another thread
1114+
with loop_in_thread() as loop:
1115+
# Create a coroutine
1116+
coro = asyncio.sleep(1, result=3)
1117+
1118+
# Submit the coroutine to a given loop
1119+
future = asyncio.run_coroutine_threadsafe(coro, loop)
1120+
1121+
# Wait for the result with an optional timeout argument
1122+
assert future.result(timeout=2) == 3
10781123

10791124
If an exception is raised in the coroutine, the returned Future
10801125
will be notified. It can also be used to cancel the task in

Doc/library/calendar.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
138138

139139
:class:`TextCalendar` instances have the following methods:
140140

141+
.. method:: formatweek(theweek, w=0)
142+
143+
Return a single week in a string with no newline. If *w* is provided, it
144+
specifies the width of the date columns, which are centered. Depends
145+
on the first weekday as specified in the constructor or set by the
146+
:meth:`setfirstweekday` method.
147+
148+
141149
.. method:: formatmonth(theyear, themonth, w=0, l=0)
142150

143151
Return a month's calendar in a multi-line string. If *w* is provided, it

Doc/library/socket.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,14 @@ Constants
674674

675675
.. availability:: Linux >= 3.9
676676

677+
.. data:: SO_REUSEPORT_LB
678+
679+
Constant to enable duplicate address and port bindings with load balancing.
680+
681+
.. versionadded:: next
682+
683+
.. availability:: FreeBSD >= 12.0
684+
677685
.. data:: AF_HYPERV
678686
HV_PROTOCOL_RAW
679687
HVSOCKET_CONNECT_TIMEOUT

Doc/library/ssl.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,12 @@ Constants
934934

935935
.. versionadded:: 3.13
936936

937+
.. data:: HAS_PHA
938+
939+
Whether the OpenSSL library has built-in support for TLS-PHA.
940+
941+
.. versionadded:: next
942+
937943
.. data:: CHANNEL_BINDING_TYPES
938944

939945
List of supported TLS channel binding types. Strings in this list

0 commit comments

Comments
 (0)