Skip to content

Commit 48eb2ec

Browse files
Merge branch 'main' into fix-issue-XXXXX
2 parents 573ec0b + 12b5a3c commit 48eb2ec

File tree

428 files changed

+18009
-21555
lines changed

Some content is hidden

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

428 files changed

+18009
-21555
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Doc/library/token-list.inc generated
6969
Include/internal/pycore_ast.h generated
7070
Include/internal/pycore_ast_state.h generated
7171
Include/internal/pycore_opcode.h generated
72-
Include/internal/pycore_runtime_init_generated.h generated
72+
Include/internal/pycore_*_generated.h generated
7373
Include/opcode.h generated
7474
Include/token.h generated
7575
Lib/keyword.py generated

.github/CODEOWNERS

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Python/traceback.c @iritkatriel
6363
# bytecode.
6464
**/*import*.c @brettcannon @encukou @ericsnowcurrently @ncoghlan @warsaw
6565
**/*import*.py @brettcannon @encukou @ericsnowcurrently @ncoghlan @warsaw
66-
**/*importlib/resources/* @jaraco @warsaw @brettcannon
66+
**/*importlib/resources/* @jaraco @warsaw @brettcannon @FFY00
6767
**/importlib/metadata/* @jaraco @warsaw
6868

6969
# Dates and times
@@ -137,8 +137,6 @@ Lib/ast.py @isidentical
137137

138138
**/*typing* @gvanrossum @Fidget-Spinner @JelleZijlstra @AlexWaygood
139139

140-
**/*asyncore @giampaolo
141-
**/*asynchat @giampaolo
142140
**/*ftplib @giampaolo
143141
**/*shutil @giampaolo
144142

@@ -148,6 +146,8 @@ Lib/ast.py @isidentical
148146

149147
**/*tomllib* @encukou
150148

149+
**/*sysconfig* @FFY00
150+
151151
# macOS
152152
/Mac/ @python/macos-team
153153
**/*osx_support* @python/macos-team

.github/workflows/build.yml

+3-3
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

+21
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ See also :ref:`Reflection <reflection>`.
7979
.. versionadded:: 3.11
8080
8181
82+
.. c:function:: PyObject* PyFrame_GetVar(PyFrameObject *frame, PyObject *name)
83+
84+
Get the variable *name* of *frame*.
85+
86+
* Return a :term:`strong reference` to the variable value on success.
87+
* Raise :exc:`NameError` and return ``NULL`` if the variable does not exist.
88+
* Raise an exception and return ``NULL`` on error.
89+
90+
*name* type must be a :class:`str`.
91+
92+
.. versionadded:: 3.12
93+
94+
95+
.. c:function:: PyObject* PyFrame_GetVarString(PyFrameObject *frame, const char *name)
96+
97+
Similar to :c:func:`PyFrame_GetVar`, but the variable name is a C string
98+
encoded in UTF-8.
99+
100+
.. versionadded:: 3.12
101+
102+
82103
.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
83104
84105
Get the *frame*'s ``f_locals`` attribute (:class:`dict`).

Doc/c-api/refcounting.rst

+44-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
Reference Counting
88
******************
99

10-
The macros in this section are used for managing reference counts of Python
11-
objects.
10+
The functions and macros in this section are used for managing reference counts
11+
of Python objects.
1212

1313

1414
.. c:function:: Py_ssize_t Py_REFCNT(PyObject *o)
@@ -129,6 +129,11 @@ objects.
129129
It is a good idea to use this macro whenever decrementing the reference
130130
count of an object that might be traversed during garbage collection.
131131
132+
.. versionchanged:: 3.12
133+
The macro argument is now only evaluated once. If the argument has side
134+
effects, these are no longer duplicated.
135+
136+
132137
.. c:function:: void Py_IncRef(PyObject *o)
133138
134139
Increment the reference count for object *o*. A function version of :c:func:`Py_XINCREF`.
@@ -139,3 +144,40 @@ objects.
139144
140145
Decrement the reference count for object *o*. A function version of :c:func:`Py_XDECREF`.
141146
It can be used for runtime dynamic embedding of Python.
147+
148+
149+
.. c:macro:: Py_SETREF(dst, src)
150+
151+
Macro safely decrementing the `dst` reference count and setting `dst` to
152+
`src`.
153+
154+
As in case of :c:func:`Py_CLEAR`, "the obvious" code can be deadly::
155+
156+
Py_DECREF(dst);
157+
dst = src;
158+
159+
The safe way is::
160+
161+
Py_SETREF(dst, src);
162+
163+
That arranges to set `dst` to `src` _before_ decrementing reference count of
164+
*dst* old value, so that any code triggered as a side-effect of `dst`
165+
getting torn down no longer believes `dst` points to a valid object.
166+
167+
.. versionadded:: 3.6
168+
169+
.. versionchanged:: 3.12
170+
The macro arguments are now only evaluated once. If an argument has side
171+
effects, these are no longer duplicated.
172+
173+
174+
.. c:macro:: Py_XSETREF(dst, src)
175+
176+
Variant of :c:macro:`Py_SETREF` macro that uses :c:func:`Py_XDECREF` instead
177+
of :c:func:`Py_DECREF`.
178+
179+
.. versionadded:: 3.6
180+
181+
.. versionchanged:: 3.12
182+
The macro arguments are now only evaluated once. If an argument has side
183+
effects, these are no longer duplicated.

Doc/faq/programming.rst

+15-3
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

+47-4
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
@@ -1299,7 +1342,7 @@ enumerations)::
12991342
DuplicateFreeEnum
13001343
^^^^^^^^^^^^^^^^^
13011344

1302-
Raises an error if a duplicate member name is found instead of creating an
1345+
Raises an error if a duplicate member value is found instead of creating an
13031346
alias::
13041347

13051348
>>> class DuplicateFreeEnum(Enum):

Doc/includes/custom2.c

+3-7
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

+7-15
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
}

0 commit comments

Comments
 (0)