Skip to content

Commit d81766d

Browse files
committed
Merge remote-tracking branch 'python/main' into pythongh-102153
2 parents 716e1c2 + 401d7a7 commit d81766d

File tree

144 files changed

+1539
-511
lines changed

Some content is hidden

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

144 files changed

+1539
-511
lines changed

Doc/c-api/code.rst

+14-3
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,27 @@ bound into a function.
172172
before the destruction of *co* takes place, so the prior state of *co*
173173
can be inspected.
174174
175+
If *event* is ``PY_CODE_EVENT_DESTROY``, taking a reference in the callback
176+
to the about-to-be-destroyed code object will resurrect it and prevent it
177+
from being freed at this time. When the resurrected object is destroyed
178+
later, any watcher callbacks active at that time will be called again.
179+
175180
Users of this API should not rely on internal runtime implementation
176181
details. Such details may include, but are not limited to, the exact
177182
order and timing of creation and destruction of code objects. While
178183
changes in these details may result in differences observable by watchers
179184
(including whether a callback is invoked or not), it does not change
180185
the semantics of the Python code being executed.
181186
182-
If the callback returns with an exception set, it must return ``-1``; this
183-
exception will be printed as an unraisable exception using
184-
:c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``.
187+
If the callback sets an exception, it must return ``-1``; this exception will
188+
be printed as an unraisable exception using :c:func:`PyErr_WriteUnraisable`.
189+
Otherwise it should return ``0``.
190+
191+
There may already be a pending exception set on entry to the callback. In
192+
this case, the callback should return ``0`` with the same exception still
193+
set. This means the callback may not call any other API that can set an
194+
exception unless it saves and clears the exception state first, and restores
195+
it before returning.
185196
186197
.. versionadded:: 3.12
187198

Doc/c-api/dict.rst

+17-4
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,26 @@ Dictionary Objects
298298
dictionary.
299299
300300
The callback may inspect but must not modify *dict*; doing so could have
301-
unpredictable effects, including infinite recursion.
301+
unpredictable effects, including infinite recursion. Do not trigger Python
302+
code execution in the callback, as it could modify the dict as a side effect.
303+
304+
If *event* is ``PyDict_EVENT_DEALLOCATED``, taking a new reference in the
305+
callback to the about-to-be-destroyed dictionary will resurrect it and
306+
prevent it from being freed at this time. When the resurrected object is
307+
destroyed later, any watcher callbacks active at that time will be called
308+
again.
302309
303310
Callbacks occur before the notified modification to *dict* takes place, so
304311
the prior state of *dict* can be inspected.
305312
306-
If the callback returns with an exception set, it must return ``-1``; this
307-
exception will be printed as an unraisable exception using
308-
:c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``.
313+
If the callback sets an exception, it must return ``-1``; this exception will
314+
be printed as an unraisable exception using :c:func:`PyErr_WriteUnraisable`.
315+
Otherwise it should return ``0``.
316+
317+
There may already be a pending exception set on entry to the callback. In
318+
this case, the callback should return ``0`` with the same exception still
319+
set. This means the callback may not call any other API that can set an
320+
exception unless it saves and clears the exception state first, and restores
321+
it before returning.
309322
310323
.. versionadded:: 3.12

Doc/c-api/function.rst

+14-3
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,19 @@ There are a few functions specific to Python functions.
173173
runtime behavior depending on optimization decisions, it does not change
174174
the semantics of the Python code being executed.
175175
176-
If the callback returns with an exception set, it must return ``-1``; this
177-
exception will be printed as an unraisable exception using
178-
:c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``.
176+
If *event* is ``PyFunction_EVENT_DESTROY``, Taking a reference in the
177+
callback to the about-to-be-destroyed function will resurrect it, preventing
178+
it from being freed at this time. When the resurrected object is destroyed
179+
later, any watcher callbacks active at that time will be called again.
180+
181+
If the callback sets an exception, it must return ``-1``; this exception will
182+
be printed as an unraisable exception using :c:func:`PyErr_WriteUnraisable`.
183+
Otherwise it should return ``0``.
184+
185+
There may already be a pending exception set on entry to the callback. In
186+
this case, the callback should return ``0`` with the same exception still
187+
set. This means the callback may not call any other API that can set an
188+
exception unless it saves and clears the exception state first, and restores
189+
it before returning.
179190
180191
.. versionadded:: 3.12

Doc/distributing/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ Key terms
3939
developers and documentation authors responsible for the maintenance and
4040
evolution of the standard packaging tools and the associated metadata and
4141
file format standards. They maintain a variety of tools, documentation
42-
and issue trackers on both `GitHub <https://github.com/pypa>`__ and
43-
`Bitbucket <https://bitbucket.org/pypa/>`__.
42+
and issue trackers on `GitHub <https://github.com/pypa>`__.
4443
* ``distutils`` is the original build and distribution system first added
4544
to the Python standard library in 1998. While direct use of ``distutils``
4645
is being phased out, it still laid the foundation for the current packaging

Doc/installing/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ Key terms
5252
developers and documentation authors responsible for the maintenance and
5353
evolution of the standard packaging tools and the associated metadata and
5454
file format standards. They maintain a variety of tools, documentation,
55-
and issue trackers on both `GitHub <https://github.com/pypa>`__ and
56-
`Bitbucket <https://bitbucket.org/pypa/>`__.
55+
and issue trackers on `GitHub <https://github.com/pypa>`__.
5756
* ``distutils`` is the original build and distribution system first added to
5857
the Python standard library in 1998. While direct use of ``distutils`` is
5958
being phased out, it still laid the foundation for the current packaging

Doc/library/argparse.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ around an instance of :class:`argparse.ArgumentParser`. It is a container for
3434
argument specifications and has options that apply to the parser as whole::
3535

3636
parser = argparse.ArgumentParser(
37-
prog = 'ProgramName',
38-
description = 'What the program does',
39-
epilog = 'Text at the bottom of help')
37+
prog='ProgramName',
38+
description='What the program does',
39+
epilog='Text at the bottom of help')
4040

4141
The :meth:`ArgumentParser.add_argument` method attaches individual argument
4242
specifications to the parser. It supports positional arguments, options that

Doc/library/venv.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ subclass which installs setuptools and pip into a created virtual environment::
478478
:param context: The information for the virtual environment
479479
creation request being processed.
480480
"""
481-
url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
481+
url = "https://bootstrap.pypa.io/ez_setup.py"
482482
self.install_script(context, 'setuptools', url)
483483
# clear up the setuptools archive which gets downloaded
484484
pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz')

Doc/library/zipapp.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ using the :func:`create_archive` function::
215215
>>> import zipapp
216216
>>> zipapp.create_archive('old_archive.pyz', 'new_archive.pyz', '/usr/bin/python3')
217217

218-
To update the file in place, do the replacement in memory using a :class:`BytesIO`
218+
To update the file in place, do the replacement in memory using a :class:`~io.BytesIO`
219219
object, and then overwrite the source afterwards. Note that there is a risk
220220
when overwriting a file in place that an error will result in the loss of
221221
the original file. This code does not protect against such errors, but

Doc/library/zipfile.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ ZipFile Objects
288288
(``ZipExtFile``) is read-only and provides the following methods:
289289
:meth:`~io.BufferedIOBase.read`, :meth:`~io.IOBase.readline`,
290290
:meth:`~io.IOBase.readlines`, :meth:`~io.IOBase.seek`,
291-
:meth:`~io.IOBase.tell`, :meth:`__iter__`, :meth:`~iterator.__next__`.
291+
:meth:`~io.IOBase.tell`, :meth:`~container.__iter__`, :meth:`~iterator.__next__`.
292292
These objects can operate independently of the ZipFile.
293293

294294
With ``mode='w'``, a writable file handle is returned, which supports the

Include/cpython/code.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,14 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
224224

225225
PyAPI_FUNC(int) PyCode_Addr2Location(PyCodeObject *, int, int *, int *, int *, int *);
226226

227-
typedef enum PyCodeEvent {
228-
PY_CODE_EVENT_CREATE,
229-
PY_CODE_EVENT_DESTROY
227+
#define PY_FOREACH_CODE_EVENT(V) \
228+
V(CREATE) \
229+
V(DESTROY)
230+
231+
typedef enum {
232+
#define PY_DEF_EVENT(op) PY_CODE_EVENT_##op,
233+
PY_FOREACH_CODE_EVENT(PY_DEF_EVENT)
234+
#undef PY_DEF_EVENT
230235
} PyCodeEvent;
231236

232237

@@ -236,7 +241,7 @@ typedef enum PyCodeEvent {
236241
* The callback is invoked with a borrowed reference to co, after it is
237242
* created and before it is destroyed.
238243
*
239-
* If the callback returns with an exception set, it must return -1. Otherwise
244+
* If the callback sets an exception, it must return -1. Otherwise
240245
* it should return 0.
241246
*/
242247
typedef int (*PyCode_WatchCallback)(

Include/cpython/dictobject.h

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ typedef struct {
1616

1717
/* Dictionary version: globally unique, value change each time
1818
the dictionary is modified */
19-
#ifdef Py_BUILD_CORE
19+
#ifdef Py_BUILD_CORE
2020
uint64_t ma_version_tag;
2121
#else
2222
Py_DEPRECATED(3.12) uint64_t ma_version_tag;
23-
#endif
23+
#endif
2424

2525
PyDictKeysObject *ma_keys;
2626

@@ -90,13 +90,18 @@ PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);
9090

9191
/* Dictionary watchers */
9292

93+
#define PY_FOREACH_DICT_EVENT(V) \
94+
V(ADDED) \
95+
V(MODIFIED) \
96+
V(DELETED) \
97+
V(CLONED) \
98+
V(CLEARED) \
99+
V(DEALLOCATED)
100+
93101
typedef enum {
94-
PyDict_EVENT_ADDED,
95-
PyDict_EVENT_MODIFIED,
96-
PyDict_EVENT_DELETED,
97-
PyDict_EVENT_CLONED,
98-
PyDict_EVENT_CLEARED,
99-
PyDict_EVENT_DEALLOCATED,
102+
#define PY_DEF_EVENT(EVENT) PyDict_EVENT_##EVENT,
103+
PY_FOREACH_DICT_EVENT(PY_DEF_EVENT)
104+
#undef PY_DEF_EVENT
100105
} PyDict_WatchEvent;
101106

102107
// Callback to be invoked when a watched dict is cleared, dealloced, or modified.

Include/cpython/funcobject.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
131131
PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
132132
PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
133133

134-
#define FOREACH_FUNC_EVENT(V) \
135-
V(CREATE) \
136-
V(DESTROY) \
137-
V(MODIFY_CODE) \
138-
V(MODIFY_DEFAULTS) \
134+
#define PY_FOREACH_FUNC_EVENT(V) \
135+
V(CREATE) \
136+
V(DESTROY) \
137+
V(MODIFY_CODE) \
138+
V(MODIFY_DEFAULTS) \
139139
V(MODIFY_KWDEFAULTS)
140140

141141
typedef enum {
142-
#define DEF_EVENT(EVENT) PyFunction_EVENT_##EVENT,
143-
FOREACH_FUNC_EVENT(DEF_EVENT)
144-
#undef DEF_EVENT
142+
#define PY_DEF_EVENT(EVENT) PyFunction_EVENT_##EVENT,
143+
PY_FOREACH_FUNC_EVENT(PY_DEF_EVENT)
144+
#undef PY_DEF_EVENT
145145
} PyFunction_WatchEvent;
146146

147147
/*

Include/internal/pycore_dict.h

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ _PyDict_NotifyEvent(PyDict_WatchEvent event,
164164
PyObject *key,
165165
PyObject *value)
166166
{
167+
assert(Py_REFCNT((PyObject*)mp) > 0);
167168
int watcher_bits = mp->ma_version_tag & DICT_VERSION_MASK;
168169
if (watcher_bits) {
169170
_PyDict_SendEvent(watcher_bits, event, mp, key, value);

Include/patchlevel.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#define PY_MINOR_VERSION 12
2121
#define PY_MICRO_VERSION 0
2222
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA
23-
#define PY_RELEASE_SERIAL 5
23+
#define PY_RELEASE_SERIAL 6
2424

2525
/* Version as a string */
26-
#define PY_VERSION "3.12.0a5+"
26+
#define PY_VERSION "3.12.0a6+"
2727
/*--end constants--*/
2828

2929
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.

Lib/_pylong.py

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
tricky or non-obvious code is not worth it. For people looking for
1313
maximum performance, they should use something like gmpy2."""
1414

15-
import sys
1615
import re
1716
import decimal
1817

Lib/concurrent/futures/process.py

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
from concurrent.futures import _base
5050
import queue
5151
import multiprocessing as mp
52+
# This import is required to load the multiprocessing.connection submodule
53+
# so that it can be accessed later as `mp.connection`
5254
import multiprocessing.connection
5355
from multiprocessing.queues import Queue
5456
import threading

Lib/dataclasses.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import types
55
import inspect
66
import keyword
7-
import builtins
87
import functools
98
import itertools
109
import abc

Lib/importlib/_abc.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Subset of importlib.abc used to reduce importlib.util imports."""
22
from . import _bootstrap
33
import abc
4-
import warnings
54

65

76
class Loader(metaclass=abc.ABCMeta):

0 commit comments

Comments
 (0)