Skip to content

Commit 9804bba

Browse files
committed
Merge branch 'main' into func-watchers
2 parents e0601c1 + 2781ec9 commit 9804bba

File tree

416 files changed

+19462
-13120
lines changed

Some content is hidden

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

416 files changed

+19462
-13120
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176
needs: check_source
177177
if: needs.check_source.outputs.run_tests == 'true'
178178
env:
179-
OPENSSL_VER: 1.1.1q
179+
OPENSSL_VER: 1.1.1s
180180
PYTHONSTRICTEXTENSIONBUILD: 1
181181
steps:
182182
- uses: actions/checkout@v3
@@ -235,7 +235,7 @@ jobs:
235235
strategy:
236236
fail-fast: false
237237
matrix:
238-
openssl_ver: [1.1.1q, 3.0.5]
238+
openssl_ver: [1.1.1s, 3.0.7]
239239
env:
240240
OPENSSL_VER: ${{ matrix.openssl_ver }}
241241
MULTISSL_DIR: ${{ github.workspace }}/multissl
@@ -282,7 +282,7 @@ jobs:
282282
needs: check_source
283283
if: needs.check_source.outputs.run_tests == 'true'
284284
env:
285-
OPENSSL_VER: 1.1.1q
285+
OPENSSL_VER: 1.1.1s
286286
PYTHONSTRICTEXTENSIONBUILD: 1
287287
ASAN_OPTIONS: detect_leaks=0:allocator_may_return_null=1:handle_segv=0
288288
steps:

Doc/c-api/frame.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ See also :ref:`Reflection <reflection>`.
8787
* Raise :exc:`NameError` and return ``NULL`` if the variable does not exist.
8888
* Raise an exception and return ``NULL`` on error.
8989
90+
*name* type must be a :class:`str`.
91+
9092
.. versionadded:: 3.12
9193
9294

Doc/c-api/init_config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ PyPreConfig
254254
255255
.. c:member:: int configure_locale
256256
257-
Set the LC_CTYPE locale to the user preferred locale?
257+
Set the LC_CTYPE locale to the user preferred locale.
258258
259259
If equals to ``0``, set :c:member:`~PyPreConfig.coerce_c_locale` and
260260
:c:member:`~PyPreConfig.coerce_c_locale_warn` members to ``0``.

Doc/faq/programming.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,25 @@ Or, you can use an extension that provides a matrix datatype; `NumPy
12791279
<https://numpy.org/>`_ is the best known.
12801280

12811281

1282-
How do I apply a method to a sequence of objects?
1283-
-------------------------------------------------
1282+
How do I apply a method or function to a sequence of objects?
1283+
-------------------------------------------------------------
12841284

1285-
Use a list comprehension::
1285+
To call a method or function and accumulate the return values is a list,
1286+
a :term:`list comprehension` is an elegant solution::
12861287

12871288
result = [obj.method() for obj in mylist]
12881289

1290+
result = [function(obj) for obj in mylist]
1291+
1292+
To just run the method or function without saving the return values,
1293+
a plain :keyword:`for` loop will suffice::
1294+
1295+
for obj in mylist:
1296+
obj.method()
1297+
1298+
for obj in mylist:
1299+
function(obj)
1300+
12891301
.. _faq-augmented-assignment-tuple-error:
12901302

12911303
Why does a_tuple[i] += ['item'] raise an exception when the addition works?

Doc/howto/enum.rst

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ yourself some work and use :func:`auto()` for the values::
173173
... FRIDAY = auto()
174174
... SATURDAY = auto()
175175
... SUNDAY = auto()
176+
... WEEKEND = SATURDAY | SUNDAY
176177

177178

178179
.. _enum-advanced-tutorial:
@@ -305,6 +306,10 @@ Iterating over the members of an enum does not provide the aliases::
305306

306307
>>> list(Shape)
307308
[<Shape.SQUARE: 2>, <Shape.DIAMOND: 1>, <Shape.CIRCLE: 3>]
309+
>>> list(Weekday)
310+
[<Weekday.MONDAY: 1>, <Weekday.TUESDAY: 2>, <Weekday.WEDNESDAY: 4>, <Weekday.THURSDAY: 8>, <Weekday.FRIDAY: 16>, <Weekday.SATURDAY: 32>, <Weekday.SUNDAY: 64>]
311+
312+
Note that the aliases ``Shape.ALIAS_FOR_SQUARE`` and ``Weekday.WEEKEND`` aren't shown.
308313

309314
The special attribute ``__members__`` is a read-only ordered mapping of names
310315
to members. It includes all names defined in the enumeration, including the
@@ -324,6 +329,11 @@ the enumeration members. For example, finding all the aliases::
324329
>>> [name for name, member in Shape.__members__.items() if member.name != name]
325330
['ALIAS_FOR_SQUARE']
326331

332+
.. note::
333+
334+
Aliases for flags include values with multiple flags set, such as ``3``,
335+
and no flags set, i.e. ``0``.
336+
327337

328338
Comparisons
329339
-----------
@@ -751,7 +761,7 @@ flags being set, the boolean evaluation is :data:`False`::
751761
False
752762

753763
Individual flags should have values that are powers of two (1, 2, 4, 8, ...),
754-
while combinations of flags won't::
764+
while combinations of flags will not::
755765

756766
>>> class Color(Flag):
757767
... RED = auto()
@@ -1096,8 +1106,8 @@ example of when ``KEEP`` is needed).
10961106

10971107
.. _enum-class-differences:
10981108

1099-
How are Enums different?
1100-
------------------------
1109+
How are Enums and Flags different?
1110+
----------------------------------
11011111

11021112
Enums have a custom metaclass that affects many aspects of both derived :class:`Enum`
11031113
classes and their instances (members).
@@ -1114,6 +1124,13 @@ responsible for ensuring that various other methods on the final :class:`Enum`
11141124
class are correct (such as :meth:`__new__`, :meth:`__getnewargs__`,
11151125
:meth:`__str__` and :meth:`__repr__`).
11161126

1127+
Flag Classes
1128+
^^^^^^^^^^^^
1129+
1130+
Flags have an expanded view of aliasing: to be canonical, the value of a flag
1131+
needs to be a power-of-two value, and not a duplicate name. So, in addition to the
1132+
:class:`Enum` definition of alias, a flag with no value (a.k.a. ``0``) or with more than one
1133+
power-of-two value (e.g. ``3``) is considered an alias.
11171134

11181135
Enum Members (aka instances)
11191136
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1123,9 +1140,35 @@ The most interesting thing about enum members is that they are singletons.
11231140
and then puts a custom :meth:`__new__` in place to ensure that no new ones are
11241141
ever instantiated by returning only the existing member instances.
11251142

1143+
Flag Members
1144+
^^^^^^^^^^^^
1145+
1146+
Flag members can be iterated over just like the :class:`Flag` class, and only the
1147+
canonical members will be returned. For example::
1148+
1149+
>>> list(Color)
1150+
[<Color.RED: 1>, <Color.GREEN: 2>, <Color.BLUE: 4>]
1151+
1152+
(Note that ``BLACK``, ``PURPLE``, and ``WHITE`` do not show up.)
1153+
1154+
Inverting a flag member returns the corresponding positive value,
1155+
rather than a negative value --- for example::
1156+
1157+
>>> ~Color.RED
1158+
<Color.GREEN|BLUE: 6>
1159+
1160+
Flag members have a length corresponding to the number of power-of-two values
1161+
they contain. For example::
1162+
1163+
>>> len(Color.PURPLE)
1164+
2
1165+
11261166

11271167
.. _enum-cookbook:
11281168

1169+
Enum Cookbook
1170+
-------------
1171+
11291172

11301173
While :class:`Enum`, :class:`IntEnum`, :class:`StrEnum`, :class:`Flag`, and
11311174
:class:`IntFlag` are expected to cover the majority of use-cases, they cannot

Doc/includes/custom2.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
5151

5252
if (first) {
5353
tmp = self->first;
54-
Py_INCREF(first);
55-
self->first = first;
54+
self->first = Py_NewRef(first);
5655
Py_XDECREF(tmp);
5756
}
5857
if (last) {
5958
tmp = self->last;
60-
Py_INCREF(last);
61-
self->last = last;
59+
self->last = Py_NewRef(last);
6260
Py_XDECREF(tmp);
6361
}
6462
return 0;
@@ -127,9 +125,7 @@ PyInit_custom2(void)
127125
if (m == NULL)
128126
return NULL;
129127

130-
Py_INCREF(&CustomType);
131-
if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
132-
Py_DECREF(&CustomType);
128+
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
133129
Py_DECREF(m);
134130
return NULL;
135131
}

Doc/includes/custom3.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
5151

5252
if (first) {
5353
tmp = self->first;
54-
Py_INCREF(first);
55-
self->first = first;
54+
self->first = Py_NewRef(first);
5655
Py_DECREF(tmp);
5756
}
5857
if (last) {
5958
tmp = self->last;
60-
Py_INCREF(last);
61-
self->last = last;
59+
self->last = Py_NewRef(last);
6260
Py_DECREF(tmp);
6361
}
6462
return 0;
@@ -73,8 +71,7 @@ static PyMemberDef Custom_members[] = {
7371
static PyObject *
7472
Custom_getfirst(CustomObject *self, void *closure)
7573
{
76-
Py_INCREF(self->first);
77-
return self->first;
74+
return Py_NewRef(self->first);
7875
}
7976

8077
static int
@@ -91,17 +88,15 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
9188
return -1;
9289
}
9390
tmp = self->first;
94-
Py_INCREF(value);
95-
self->first = value;
91+
self->first = Py_NewRef(value);
9692
Py_DECREF(tmp);
9793
return 0;
9894
}
9995

10096
static PyObject *
10197
Custom_getlast(CustomObject *self, void *closure)
10298
{
103-
Py_INCREF(self->last);
104-
return self->last;
99+
return Py_NewRef(self->last);
105100
}
106101

107102
static int
@@ -118,8 +113,7 @@ Custom_setlast(CustomObject *self, PyObject *value, void *closure)
118113
return -1;
119114
}
120115
tmp = self->last;
121-
Py_INCREF(value);
122-
self->last = value;
116+
self->last = Py_NewRef(value);
123117
Py_DECREF(tmp);
124118
return 0;
125119
}
@@ -178,9 +172,7 @@ PyInit_custom3(void)
178172
if (m == NULL)
179173
return NULL;
180174

181-
Py_INCREF(&CustomType);
182-
if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
183-
Py_DECREF(&CustomType);
175+
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
184176
Py_DECREF(m);
185177
return NULL;
186178
}

Doc/includes/custom4.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
6767

6868
if (first) {
6969
tmp = self->first;
70-
Py_INCREF(first);
71-
self->first = first;
70+
self->first = Py_NewRef(first);
7271
Py_DECREF(tmp);
7372
}
7473
if (last) {
7574
tmp = self->last;
76-
Py_INCREF(last);
77-
self->last = last;
75+
self->last = Py_NewRef(last);
7876
Py_DECREF(tmp);
7977
}
8078
return 0;
@@ -89,8 +87,7 @@ static PyMemberDef Custom_members[] = {
8987
static PyObject *
9088
Custom_getfirst(CustomObject *self, void *closure)
9189
{
92-
Py_INCREF(self->first);
93-
return self->first;
90+
return Py_NewRef(self->first);
9491
}
9592

9693
static int
@@ -114,8 +111,7 @@ Custom_setfirst(CustomObject *self, PyObject *value, void *closure)
114111
static PyObject *
115112
Custom_getlast(CustomObject *self, void *closure)
116113
{
117-
Py_INCREF(self->last);
118-
return self->last;
114+
return Py_NewRef(self->last);
119115
}
120116

121117
static int
@@ -192,9 +188,7 @@ PyInit_custom4(void)
192188
if (m == NULL)
193189
return NULL;
194190

195-
Py_INCREF(&CustomType);
196-
if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
197-
Py_DECREF(&CustomType);
191+
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
198192
Py_DECREF(m);
199193
return NULL;
200194
}

Doc/library/_thread.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ This module defines the following constants and functions:
5757
When the function raises a :exc:`SystemExit` exception, it is silently
5858
ignored.
5959

60+
.. audit-event:: _thread.start_new_thread function,args,kwargs start_new_thread
61+
6062
.. versionchanged:: 3.8
6163
:func:`sys.unraisablehook` is now used to handle unhandled exceptions.
6264

Doc/library/asyncio-policy.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ implementation used by the asyncio event loop:
222222
This method has to be called to ensure that underlying
223223
resources are cleaned-up.
224224

225+
.. deprecated:: 3.12
226+
227+
225228
.. class:: ThreadedChildWatcher
226229

227230
This implementation starts a new waiting thread for every subprocess spawn.

Doc/library/asyncio-runner.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ to simplify async code usage for common wide-spread scenarios.
2222
Running an asyncio Program
2323
==========================
2424

25-
.. function:: run(coro, *, debug=None)
25+
.. function:: run(coro, *, debug=None, loop_factory=None)
2626

2727
Execute the :term:`coroutine` *coro* and return the result.
2828

@@ -37,9 +37,11 @@ Running an asyncio Program
3737
debug mode explicitly. ``None`` is used to respect the global
3838
:ref:`asyncio-debug-mode` settings.
3939

40-
This function always creates a new event loop and closes it at
41-
the end. It should be used as a main entry point for asyncio
42-
programs, and should ideally only be called once.
40+
If *loop_factory* is not ``None``, it is used to create a new event loop;
41+
otherwise :func:`asyncio.new_event_loop` is used. The loop is closed at the end.
42+
This function should be used as a main entry point for asyncio programs,
43+
and should ideally only be called once. It is recommended to use
44+
*loop_factory* to configure the event loop instead of policies.
4345

4446
The executor is given a timeout duration of 5 minutes to shutdown.
4547
If the executor hasn't finished within that duration, a warning is
@@ -62,6 +64,10 @@ Running an asyncio Program
6264

6365
*debug* is ``None`` by default to respect the global debug mode settings.
6466

67+
.. versionchanged:: 3.12
68+
69+
Added *loop_factory* parameter.
70+
6571

6672
Runner context manager
6773
======================

Doc/library/asyncio-task.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and Tasks.
1818
Coroutines
1919
==========
2020

21+
**Source code:** :source:`Lib/asyncio/coroutines.py`
22+
23+
----------------------------------------------------
24+
2125
:term:`Coroutines <coroutine>` declared with the async/await syntax is the
2226
preferred way of writing asyncio applications. For example, the following
2327
snippet of code prints "hello", waits 1 second,
@@ -230,6 +234,10 @@ is :meth:`loop.run_in_executor`.
230234
Creating Tasks
231235
==============
232236

237+
**Source code:** :source:`Lib/asyncio/tasks.py`
238+
239+
-----------------------------------------------
240+
233241
.. function:: create_task(coro, *, name=None, context=None)
234242

235243
Wrap the *coro* :ref:`coroutine <coroutine>` into a :class:`Task`

0 commit comments

Comments
 (0)