Skip to content

Commit b465e0a

Browse files
authored
Merge branch 'main' into pythongh-99341
2 parents 543960f + c95f554 commit b465e0a

File tree

293 files changed

+11118
-16809
lines changed

Some content is hidden

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

293 files changed

+11118
-16809
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

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/call.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ This is a pointer to a function with the following signature:
9393
and they must be unique.
9494
If there are no keyword arguments, then *kwnames* can instead be *NULL*.
9595

96-
.. c:macro:: PY_VECTORCALL_ARGUMENTS_OFFSET
96+
.. data:: PY_VECTORCALL_ARGUMENTS_OFFSET
9797

9898
If this flag is set in a vectorcall *nargsf* argument, the callee is allowed
9999
to temporarily change ``args[-1]``. In other words, *args* points to

Doc/c-api/frame.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ 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+
.. versionadded:: 3.12
91+
92+
93+
.. c:function:: PyObject* PyFrame_GetVarString(PyFrameObject *frame, const char *name)
94+
95+
Similar to :c:func:`PyFrame_GetVar`, but the variable name is a C string
96+
encoded in UTF-8.
97+
98+
.. versionadded:: 3.12
99+
100+
82101
.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
83102
84103
Get the *frame*'s ``f_locals`` attribute (:class:`dict`).

Doc/c-api/refcounting.rst

Lines changed: 44 additions & 2 deletions
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/c-api/typeobj.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12451245
**Inheritance:**
12461246

12471247
This flag is not inherited.
1248+
However, subclasses will not be instantiable unless they provide a
1249+
non-NULL :c:member:`~PyTypeObject.tp_new` (which is only possible
1250+
via the C API).
1251+
1252+
.. note::
1253+
1254+
To disallow instantiating a class directly but allow instantiating
1255+
its subclasses (e.g. for an :term:`abstract base class`),
1256+
do not use this flag.
1257+
Instead, make :c:member:`~PyTypeObject.tp_new` only succeed for
1258+
subclasses.
12481259

12491260
.. versionadded:: 3.10
12501261

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/faq/windows.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ How can I embed Python into a Windows application?
167167

168168
Embedding the Python interpreter in a Windows app can be summarized as follows:
169169

170-
1. Do _not_ build Python into your .exe file directly. On Windows, Python must
170+
1. Do **not** build Python into your .exe file directly. On Windows, Python must
171171
be a DLL to handle importing modules that are themselves DLL's. (This is the
172172
first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is
173173
typically installed in ``C:\Windows\System``. *NN* is the Python version, a
@@ -191,7 +191,7 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
191191
2. If you use SWIG, it is easy to create a Python "extension module" that will
192192
make the app's data and methods available to Python. SWIG will handle just
193193
about all the grungy details for you. The result is C code that you link
194-
*into* your .exe file (!) You do _not_ have to create a DLL file, and this
194+
*into* your .exe file (!) You do **not** have to create a DLL file, and this
195195
also simplifies linking.
196196

197197
3. SWIG will create an init function (a C function) whose name depends on the
@@ -218,10 +218,10 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
218218
5. There are two problems with Python's C API which will become apparent if you
219219
use a compiler other than MSVC, the compiler used to build pythonNN.dll.
220220

221-
Problem 1: The so-called "Very High Level" functions that take FILE *
221+
Problem 1: The so-called "Very High Level" functions that take ``FILE *``
222222
arguments will not work in a multi-compiler environment because each
223-
compiler's notion of a struct FILE will be different. From an implementation
224-
standpoint these are very _low_ level functions.
223+
compiler's notion of a ``struct FILE`` will be different. From an implementation
224+
standpoint these are very low level functions.
225225

226226
Problem 2: SWIG generates the following code when generating wrappers to void
227227
functions:

Doc/howto/enum.rst

Lines changed: 47 additions & 4 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
@@ -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):

0 commit comments

Comments
 (0)