Skip to content

Commit a7b0830

Browse files
authored
Merge branch 'main' into remove_classmethod_descriptor_chaining
2 parents 8336eb0 + 4596c76 commit a7b0830

File tree

100 files changed

+1703
-468
lines changed

Some content is hidden

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

100 files changed

+1703
-468
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.0.288
3+
rev: v0.0.292
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/

Doc/c-api/object.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,21 @@ Object Protocol
489489
:c:macro:`Py_TPFLAGS_ITEMS_AT_END` set.
490490
491491
.. versionadded:: 3.12
492+
493+
.. c:function:: int PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg)
494+
495+
Visit the managed dictionary of *obj*.
496+
497+
This function must only be called in a traverse function of the type which
498+
has the :c:macro:`Py_TPFLAGS_MANAGED_DICT` flag set.
499+
500+
.. versionadded:: 3.13
501+
502+
.. c:function:: void PyObject_ClearManagedDict(PyObject *obj)
503+
504+
Clear the managed dictionary of *obj*.
505+
506+
This function must only be called in a traverse function of the type which
507+
has the :c:macro:`Py_TPFLAGS_MANAGED_DICT` flag set.
508+
509+
.. versionadded:: 3.13

Doc/c-api/typeobj.rst

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,9 @@ and :c:data:`PyType_Type` effectively act as defaults.)
11311131

11321132
If this flag is set, :c:macro:`Py_TPFLAGS_HAVE_GC` should also be set.
11331133

1134+
The type traverse function must call :c:func:`PyObject_VisitManagedDict`
1135+
and its clear function must call :c:func:`PyObject_ClearManagedDict`.
1136+
11341137
.. versionadded:: 3.12
11351138

11361139
**Inheritance:**
@@ -1368,6 +1371,23 @@ and :c:data:`PyType_Type` effectively act as defaults.)
13681371
debugging aid you may want to visit it anyway just so the :mod:`gc` module's
13691372
:func:`~gc.get_referents` function will include it.
13701373

1374+
Heap types (:c:macro:`Py_TPFLAGS_HEAPTYPE`) must visit their type with::
1375+
1376+
Py_VISIT(Py_TYPE(self));
1377+
1378+
It is only needed since Python 3.9. To support Python 3.8 and older, this
1379+
line must be conditionnal::
1380+
1381+
#if PY_VERSION_HEX >= 0x03090000
1382+
Py_VISIT(Py_TYPE(self));
1383+
#endif
1384+
1385+
If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the
1386+
:c:member:`~PyTypeObject.tp_flags` field, the traverse function must call
1387+
:c:func:`PyObject_VisitManagedDict` like this::
1388+
1389+
PyObject_VisitManagedDict((PyObject*)self, visit, arg);
1390+
13711391
.. warning::
13721392
When implementing :c:member:`~PyTypeObject.tp_traverse`, only the
13731393
members that the instance *owns* (by having :term:`strong references
@@ -1451,6 +1471,12 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14511471
so that *self* knows the contained object can no longer be used. The
14521472
:c:func:`Py_CLEAR` macro performs the operations in a safe order.
14531473

1474+
If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the
1475+
:c:member:`~PyTypeObject.tp_flags` field, the traverse function must call
1476+
:c:func:`PyObject_ClearManagedDict` like this::
1477+
1478+
PyObject_ClearManagedDict((PyObject*)self);
1479+
14541480
Note that :c:member:`~PyTypeObject.tp_clear` is not *always* called
14551481
before an instance is deallocated. For example, when reference counting
14561482
is enough to determine that an object is no longer used, the cyclic garbage
@@ -1801,7 +1827,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
18011827
field is ``NULL`` then no :attr:`~object.__dict__` gets created for instances.
18021828

18031829
If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the
1804-
:c:member:`~PyTypeObject.tp_dict` field, then
1830+
:c:member:`~PyTypeObject.tp_flags` field, then
18051831
:c:member:`~PyTypeObject.tp_dictoffset` will be set to ``-1``, to indicate
18061832
that it is unsafe to use this field.
18071833

Doc/constraints.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ colorama<0.5
1010
imagesize<1.5
1111
Jinja2<3.2
1212
packaging<24
13-
# Pygments==2.15.0 breaks CI
14-
Pygments<2.16,!=2.15.0
13+
Pygments>=2.16.1,<3
1514
requests<3
1615
snowballstemmer<3
1716
sphinxcontrib-applehelp<1.1

Doc/data/stable_abi.dat

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/library/__main__.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ package. For more details, see :ref:`intra-package-references` in the
238238
Idiomatic Usage
239239
^^^^^^^^^^^^^^^
240240

241-
The contents of ``__main__.py`` typically isn't fenced with
242-
``if __name__ == '__main__'`` blocks. Instead, those files are kept short,
243-
functions to execute from other modules. Those other modules can then be
241+
The content of ``__main__.py`` typically isn't fenced with an
242+
``if __name__ == '__main__'`` block. Instead, those files are kept
243+
short and import functions to execute from other modules. Those other modules can then be
244244
easily unit-tested and are properly reusable.
245245

246246
If used, an ``if __name__ == '__main__'`` block will still work as expected

Doc/library/compileall.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ compile Python sources.
9090
.. cmdoption:: -j N
9191

9292
Use *N* workers to compile the files within the given directory.
93-
If ``0`` is used, then the result of :func:`os.cpu_count()`
93+
If ``0`` is used, then the result of :func:`os.process_cpu_count()`
9494
will be used.
9595

9696
.. cmdoption:: --invalidation-mode [timestamp|checked-hash|unchecked-hash]

Doc/library/concurrent.futures.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ And::
188188
ThreadPoolExecutor now reuses idle worker threads before starting
189189
*max_workers* worker threads too.
190190

191+
.. versionchanged:: 3.13
192+
Default value of *max_workers* is changed to
193+
``min(32, (os.process_cpu_count() or 1) + 4)``.
194+
191195

192196
.. _threadpoolexecutor-example:
193197

@@ -243,7 +247,7 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
243247

244248
An :class:`Executor` subclass that executes calls asynchronously using a pool
245249
of at most *max_workers* processes. If *max_workers* is ``None`` or not
246-
given, it will default to the number of processors on the machine.
250+
given, it will default to :func:`os.process_cpu_count`.
247251
If *max_workers* is less than or equal to ``0``, then a :exc:`ValueError`
248252
will be raised.
249253
On Windows, *max_workers* must be less than or equal to ``61``. If it is not
@@ -301,6 +305,10 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
301305
different start method. See the :func:`os.fork` documentation for
302306
further explanation.
303307

308+
.. versionchanged:: 3.13
309+
*max_workers* uses :func:`os.process_cpu_count` by default, instead of
310+
:func:`os.cpu_count`.
311+
304312
.. _processpoolexecutor-example:
305313

306314
ProcessPoolExecutor Example

Doc/library/exceptions.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,16 @@ The following exceptions are the exceptions that are usually raised.
220220
load a module. Also raised when the "from list" in ``from ... import``
221221
has a name that cannot be found.
222222

223-
The :attr:`name` and :attr:`path` attributes can be set using keyword-only
224-
arguments to the constructor. When set they represent the name of the module
225-
that was attempted to be imported and the path to any file which triggered
226-
the exception, respectively.
223+
The optional *name* and *path* keyword-only arguments
224+
set the corresponding attributes:
225+
226+
.. attribute:: name
227+
228+
The name of the module that was attempted to be imported.
229+
230+
.. attribute:: path
231+
232+
The path to any file which triggered the exception.
227233

228234
.. versionchanged:: 3.3
229235
Added the :attr:`name` and :attr:`path` attributes.

Doc/library/multiprocessing.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,13 +996,13 @@ Miscellaneous
996996

997997
This number is not equivalent to the number of CPUs the current process can
998998
use. The number of usable CPUs can be obtained with
999-
``len(os.sched_getaffinity(0))``
999+
:func:`os.process_cpu_count`.
10001000

10011001
When the number of CPUs cannot be determined a :exc:`NotImplementedError`
10021002
is raised.
10031003

10041004
.. seealso::
1005-
:func:`os.cpu_count`
1005+
:func:`os.cpu_count` and :func:`os.process_cpu_count`
10061006

10071007
.. function:: current_process()
10081008

@@ -2214,7 +2214,7 @@ with the :class:`Pool` class.
22142214
callbacks and has a parallel map implementation.
22152215

22162216
*processes* is the number of worker processes to use. If *processes* is
2217-
``None`` then the number returned by :func:`os.cpu_count` is used.
2217+
``None`` then the number returned by :func:`os.process_cpu_count` is used.
22182218

22192219
If *initializer* is not ``None`` then each worker process will call
22202220
``initializer(*initargs)`` when it starts.
@@ -2249,6 +2249,10 @@ with the :class:`Pool` class.
22492249
.. versionadded:: 3.4
22502250
*context*
22512251

2252+
.. versionchanged:: 3.13
2253+
*processes* uses :func:`os.process_cpu_count` by default, instead of
2254+
:func:`os.cpu_count`.
2255+
22522256
.. note::
22532257

22542258
Worker processes within a :class:`Pool` typically live for the complete
@@ -2775,7 +2779,7 @@ worker threads rather than worker processes.
27752779
:meth:`~multiprocessing.pool.Pool.terminate` manually.
27762780

27772781
*processes* is the number of worker threads to use. If *processes* is
2778-
``None`` then the number returned by :func:`os.cpu_count` is used.
2782+
``None`` then the number returned by :func:`os.process_cpu_count` is used.
27792783

27802784
If *initializer* is not ``None`` then each worker process will call
27812785
``initializer(*initargs)`` when it starts.

Doc/library/os.rst

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,8 +5141,12 @@ operating system.
51415141

51425142
.. function:: sched_getaffinity(pid, /)
51435143

5144-
Return the set of CPUs the process with PID *pid* (or the current process
5145-
if zero) is restricted to.
5144+
Return the set of CPUs the process with PID *pid* is restricted to.
5145+
5146+
If *pid* is zero, return the set of CPUs the calling thread of the current
5147+
process is restricted to.
5148+
5149+
See also the :func:`process_cpu_count` function.
51465150

51475151

51485152
.. _os-path:
@@ -5183,12 +5187,11 @@ Miscellaneous System Information
51835187

51845188
.. function:: cpu_count()
51855189

5186-
Return the number of CPUs in the system. Returns ``None`` if undetermined.
5187-
5188-
This number is not equivalent to the number of CPUs the current process can
5189-
use. The number of usable CPUs can be obtained with
5190-
``len(os.sched_getaffinity(0))``
5190+
Return the number of logical CPUs in the **system**. Returns ``None`` if
5191+
undetermined.
51915192

5193+
The :func:`process_cpu_count` function can be used to get the number of
5194+
logical CPUs usable by the calling thread of the **current process**.
51925195

51935196
.. versionadded:: 3.4
51945197

@@ -5202,6 +5205,20 @@ Miscellaneous System Information
52025205
.. availability:: Unix.
52035206

52045207

5208+
.. function:: process_cpu_count()
5209+
5210+
Get the number of logical CPUs usable by the calling thread of the **current
5211+
process**. Returns ``None`` if undetermined. It can be less than
5212+
:func:`cpu_count` depending on the CPU affinity.
5213+
5214+
The :func:`cpu_count` function can be used to get the number of logical CPUs
5215+
in the **system**.
5216+
5217+
See also the :func:`sched_getaffinity` functions.
5218+
5219+
.. versionadded:: 3.13
5220+
5221+
52055222
.. function:: sysconf(name, /)
52065223

52075224
Return integer-valued system configuration values. If the configuration value

Doc/library/pathlib.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,42 @@ call fails (for example because the path doesn't exist).
850850
.. versionadded:: 3.5
851851

852852

853+
.. classmethod:: Path.from_uri(uri)
854+
855+
Return a new path object from parsing a 'file' URI conforming to
856+
:rfc:`8089`. For example::
857+
858+
>>> p = Path.from_uri('file:///etc/hosts')
859+
PosixPath('/etc/hosts')
860+
861+
On Windows, DOS device and UNC paths may be parsed from URIs::
862+
863+
>>> p = Path.from_uri('file:///c:/windows')
864+
WindowsPath('c:/windows')
865+
>>> p = Path.from_uri('file://server/share')
866+
WindowsPath('//server/share')
867+
868+
Several variant forms are supported::
869+
870+
>>> p = Path.from_uri('file:////server/share')
871+
WindowsPath('//server/share')
872+
>>> p = Path.from_uri('file://///server/share')
873+
WindowsPath('//server/share')
874+
>>> p = Path.from_uri('file:c:/windows')
875+
WindowsPath('c:/windows')
876+
>>> p = Path.from_uri('file:/c|/windows')
877+
WindowsPath('c:/windows')
878+
879+
:exc:`ValueError` is raised if the URI does not start with ``file:``, or
880+
the parsed path isn't absolute.
881+
882+
:func:`os.fsdecode` is used to decode percent-escaped byte sequences, and
883+
so file URIs are not portable across machines with different
884+
:ref:`filesystem encodings <filesystem-encoding>`.
885+
886+
.. versionadded:: 3.13
887+
888+
853889
.. method:: Path.stat(*, follow_symlinks=True)
854890

855891
Return a :class:`os.stat_result` object containing information about this path, like :func:`os.stat`.

Doc/library/shutil.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ Directory and files operations
476476
or ends with an extension that is in ``PATHEXT``; and filenames that
477477
have no extension can now be found.
478478

479+
.. versionchanged:: 3.12.1
480+
On Windows, if *mode* includes ``os.X_OK``, executables with an
481+
extension in ``PATHEXT`` will be preferred over executables without a
482+
matching extension.
483+
This brings behavior closer to that of Python 3.11.
484+
479485
.. exception:: Error
480486

481487
This exception collects exceptions that are raised during a multi-file

Doc/library/site.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Importing this module will append site-specific paths to the module search path
1919
and add a few builtins, unless :option:`-S` was used. In that case, this module
2020
can be safely imported with no automatic modifications to the module search path
2121
or additions to the builtins. To explicitly trigger the usual site-specific
22-
additions, call the :func:`site.main` function.
22+
additions, call the :func:`main` function.
2323

2424
.. versionchanged:: 3.3
2525
Importing the module used to trigger paths manipulation even when using
@@ -109,32 +109,40 @@ directory precedes the :file:`foo` directory because :file:`bar.pth` comes
109109
alphabetically before :file:`foo.pth`; and :file:`spam` is omitted because it is
110110
not mentioned in either path configuration file.
111111

112-
.. index:: pair: module; sitecustomize
112+
:mod:`sitecustomize`
113+
--------------------
114+
115+
.. module:: sitecustomize
113116

114117
After these path manipulations, an attempt is made to import a module named
115118
:mod:`sitecustomize`, which can perform arbitrary site-specific customizations.
116119
It is typically created by a system administrator in the site-packages
117120
directory. If this import fails with an :exc:`ImportError` or its subclass
118-
exception, and the exception's :attr:`name` attribute equals to ``'sitecustomize'``,
121+
exception, and the exception's :attr:`~ImportError.name`
122+
attribute equals to ``'sitecustomize'``,
119123
it is silently ignored. If Python is started without output streams available, as
120124
with :file:`pythonw.exe` on Windows (which is used by default to start IDLE),
121125
attempted output from :mod:`sitecustomize` is ignored. Any other exception
122126
causes a silent and perhaps mysterious failure of the process.
123127

124-
.. index:: pair: module; usercustomize
128+
:mod:`usercustomize`
129+
--------------------
130+
131+
.. module:: usercustomize
125132

126133
After this, an attempt is made to import a module named :mod:`usercustomize`,
127134
which can perform arbitrary user-specific customizations, if
128-
:data:`ENABLE_USER_SITE` is true. This file is intended to be created in the
135+
:data:`~site.ENABLE_USER_SITE` is true. This file is intended to be created in the
129136
user site-packages directory (see below), which is part of ``sys.path`` unless
130137
disabled by :option:`-s`. If this import fails with an :exc:`ImportError` or
131-
its subclass exception, and the exception's :attr:`name` attribute equals to
132-
``'usercustomize'``, it is silently ignored.
138+
its subclass exception, and the exception's :attr:`~ImportError.name`
139+
attribute equals to ``'usercustomize'``, it is silently ignored.
133140

134141
Note that for some non-Unix systems, ``sys.prefix`` and ``sys.exec_prefix`` are
135142
empty, and the path manipulations are skipped; however the import of
136143
:mod:`sitecustomize` and :mod:`usercustomize` is still attempted.
137144

145+
.. currentmodule:: site
138146

139147
.. _rlcompleter-config:
140148

@@ -191,7 +199,7 @@ Module contents
191199
:file:`~/Library/Python/{X.Y}` for macOS framework builds, and
192200
:file:`{%APPDATA%}\\Python` for Windows. This value is used to
193201
compute the installation directories for scripts, data files, Python modules,
194-
etc. for the user installation scheme.
202+
etc. for the :ref:`user installation scheme <sysconfig-user-scheme>`.
195203
See also :envvar:`PYTHONUSERBASE`.
196204

197205

0 commit comments

Comments
 (0)