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.

0 commit comments

Comments
 (0)