Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f45d6a4

Browse files
committed
Merge branch 'main' into remove-imp
2 parents c240e08 + 534660f commit f45d6a4

File tree

267 files changed

+5731
-1102
lines changed

Some content is hidden

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

267 files changed

+5731
-1102
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/dataclasses.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Module contents
389389
:func:`astuple` raises :exc:`TypeError` if ``obj`` is not a dataclass
390390
instance.
391391

392-
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)
392+
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None)
393393

394394
Creates a new dataclass with name ``cls_name``, fields as defined
395395
in ``fields``, base classes as given in ``bases``, and initialized
@@ -401,6 +401,10 @@ Module contents
401401
``match_args``, ``kw_only``, ``slots``, and ``weakref_slot`` have
402402
the same meaning as they do in :func:`dataclass`.
403403

404+
If ``module`` is defined, the ``__module__`` attribute
405+
of the dataclass is set to that value.
406+
By default, it is set to the module name of the caller.
407+
404408
This function is not strictly required, because any Python
405409
mechanism for creating a new class with ``__annotations__`` can
406410
then apply the :func:`dataclass` function to convert that class to

Doc/library/dis.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ the following command can be used to display the disassembly of
5757
2 0 RESUME 0
5858
<BLANKLINE>
5959
3 2 LOAD_GLOBAL 1 (NULL + len)
60-
14 LOAD_FAST 0 (alist)
61-
16 CALL 1
62-
26 RETURN_VALUE
60+
12 LOAD_FAST 0 (alist)
61+
14 CALL 1
62+
24 RETURN_VALUE
6363

6464
(The "2" is a line number).
6565

Doc/library/inspect.rst

+26-2
Original file line numberDiff line numberDiff line change
@@ -1440,8 +1440,8 @@ code execution::
14401440
pass
14411441

14421442

1443-
Current State of Generators and Coroutines
1444-
------------------------------------------
1443+
Current State of Generators, Coroutines, and Asynchronous Generators
1444+
--------------------------------------------------------------------
14451445

14461446
When implementing coroutine schedulers and for other advanced uses of
14471447
generators, it is useful to determine whether a generator is currently
@@ -1476,6 +1476,22 @@ generator to be determined easily.
14761476

14771477
.. versionadded:: 3.5
14781478

1479+
.. function:: getasyncgenstate(agen)
1480+
1481+
Get current state of an asynchronous generator object. The function is
1482+
intended to be used with asynchronous iterator objects created by
1483+
:keyword:`async def` functions which use the :keyword:`yield` statement,
1484+
but will accept any asynchronous generator-like object that has
1485+
``ag_running`` and ``ag_frame`` attributes.
1486+
1487+
Possible states are:
1488+
* AGEN_CREATED: Waiting to start execution.
1489+
* AGEN_RUNNING: Currently being executed by the interpreter.
1490+
* AGEN_SUSPENDED: Currently suspended at a yield expression.
1491+
* AGEN_CLOSED: Execution has completed.
1492+
1493+
.. versionadded:: 3.12
1494+
14791495
The current internal state of the generator can also be queried. This is
14801496
mostly useful for testing purposes, to ensure that internal state is being
14811497
updated as expected:
@@ -1507,6 +1523,14 @@ updated as expected:
15071523

15081524
.. versionadded:: 3.5
15091525

1526+
.. function:: getasyncgenlocals(agen)
1527+
1528+
This function is analogous to :func:`~inspect.getgeneratorlocals`, but
1529+
works for asynchronous generator objects created by :keyword:`async def`
1530+
functions which use the :keyword:`yield` statement.
1531+
1532+
.. versionadded:: 3.12
1533+
15101534

15111535
.. _inspect-module-co-flags:
15121536

Doc/library/os.rst

+63
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,69 @@ features:
21882188
Accepts a :term:`path-like object`.
21892189

21902190

2191+
.. function:: listdrives()
2192+
2193+
Return a list containing the names of drives on a Windows system.
2194+
2195+
A drive name typically looks like ``'C:\\'``. Not every drive name
2196+
will be associated with a volume, and some may be inaccessible for
2197+
a variety of reasons, including permissions, network connectivity
2198+
or missing media. This function does not test for access.
2199+
2200+
May raise :exc:`OSError` if an error occurs collecting the drive
2201+
names.
2202+
2203+
.. audit-event:: os.listdrives "" os.listdrives
2204+
2205+
.. availability:: Windows
2206+
2207+
.. versionadded:: 3.12
2208+
2209+
2210+
.. function:: listmounts(volume)
2211+
2212+
Return a list containing the mount points for a volume on a Windows
2213+
system.
2214+
2215+
*volume* must be represented as a GUID path, like those returned by
2216+
:func:`os.listvolumes`. Volumes may be mounted in multiple locations
2217+
or not at all. In the latter case, the list will be empty. Mount
2218+
points that are not associated with a volume will not be returned by
2219+
this function.
2220+
2221+
The mount points return by this function will be absolute paths, and
2222+
may be longer than the drive name.
2223+
2224+
Raises :exc:`OSError` if the volume is not recognized or if an error
2225+
occurs collecting the paths.
2226+
2227+
.. audit-event:: os.listmounts volume os.listmounts
2228+
2229+
.. availability:: Windows
2230+
2231+
.. versionadded:: 3.12
2232+
2233+
2234+
.. function:: listvolumes()
2235+
2236+
Return a list containing the volumes in the system.
2237+
2238+
Volumes are typically represented as a GUID path that looks like
2239+
``\\?\Volume{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\``. Files can
2240+
usually be accessed through a GUID path, permissions allowing.
2241+
However, users are generally not familiar with them, and so the
2242+
recommended use of this function is to retrieve mount points
2243+
using :func:`os.listmounts`.
2244+
2245+
May raise :exc:`OSError` if an error occurs collecting the volumes.
2246+
2247+
.. audit-event:: os.listvolumes "" os.listvolumes
2248+
2249+
.. availability:: Windows
2250+
2251+
.. versionadded:: 3.12
2252+
2253+
21912254
.. function:: lstat(path, *, dir_fd=None)
21922255

21932256
Perform the equivalent of an :c:func:`lstat` system call on the given path.

Doc/library/threading.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ The instance's values will be different for separate threads.
272272
A class that represents thread-local data.
273273

274274
For more details and extensive examples, see the documentation string of the
275-
:mod:`_threading_local` module.
275+
:mod:`_threading_local` module: :source:`Lib/_threading_local.py`.
276276

277277

278278
.. _thread-objects:

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

Doc/whatsnew/3.12.rst

+10
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ Other Language Changes
189189
part of comprehensions (like ``a``) is still disallowed, as per :pep:`572`.
190190
(Contributed by Nikita Sobolev in :gh:`100581`.)
191191

192+
* :class:`slice` objects are now hashable, allowing them to be used as dict keys and
193+
set items. (Contributed by Furkan Onder in :gh:`101264`.)
192194

193195
New Modules
194196
===========
@@ -242,6 +244,10 @@ inspect
242244
a :term:`coroutine` for use with :func:`iscoroutinefunction`.
243245
(Contributed Carlton Gibson in :gh:`99247`.)
244246

247+
* Add :func:`inspect.getasyncgenstate` and :func:`inspect.getasyncgenlocals`
248+
for determining the current state of asynchronous generators.
249+
(Contributed by Thomas Krennwallner in :issue:`35759`.)
250+
245251
pathlib
246252
-------
247253

@@ -292,6 +298,10 @@ os
292298
method to check if the entry is a junction.
293299
(Contributed by Charles Machalow in :gh:`99547`.)
294300

301+
* Add :func:`os.listdrives`, :func:`os.listvolumes` and :func:`os.listmounts`
302+
functions on Windows for enumerating drives, volumes and mount points.
303+
(Contributed by Steve Dower in :gh:`102519`.)
304+
295305
os.path
296306
-------
297307

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)(

0 commit comments

Comments
 (0)