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

Skip to content

Commit 1cb4a1f

Browse files
committed
Catch up with main
2 parents ca4956f + 4596c76 commit 1cb4a1f

127 files changed

Lines changed: 2968 additions & 1117 deletions

File tree

Some content is hidden

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

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class-based API instead.
5858

5959
Return the localized translation of *message*, based on the current global
6060
domain, language, and locale directory. This function is usually aliased as
61-
:func:`_` in the local namespace (see examples below).
61+
:func:`!_` in the local namespace (see examples below).
6262

6363

6464
.. function:: dgettext(domain, message)
@@ -98,7 +98,7 @@ class-based API instead.
9898
.. versionadded:: 3.8
9999

100100

101-
Note that GNU :program:`gettext` also defines a :func:`dcgettext` method, but
101+
Note that GNU :program:`gettext` also defines a :func:`!dcgettext` method, but
102102
this was deemed not useful and so it is currently unimplemented.
103103

104104
Here's an example of typical usage for this API::
@@ -119,7 +119,7 @@ greater convenience than the GNU :program:`gettext` API. It is the recommended
119119
way of localizing your Python applications and modules. :mod:`!gettext` defines
120120
a :class:`GNUTranslations` class which implements the parsing of GNU :file:`.mo` format
121121
files, and has methods for returning strings. Instances of this class can also
122-
install themselves in the built-in namespace as the function :func:`_`.
122+
install themselves in the built-in namespace as the function :func:`!_`.
123123

124124

125125
.. function:: find(domain, localedir=None, languages=None, all=False)
@@ -150,15 +150,12 @@ install themselves in the built-in namespace as the function :func:`_`.
150150

151151
.. function:: translation(domain, localedir=None, languages=None, class_=None, fallback=False)
152152

153-
Return a :class:`*Translations` instance based on the *domain*, *localedir*,
153+
Return a ``*Translations`` instance based on the *domain*, *localedir*,
154154
and *languages*, which are first passed to :func:`find` to get a list of the
155155
associated :file:`.mo` file paths. Instances with identical :file:`.mo` file
156156
names are cached. The actual class instantiated is *class_* if
157157
provided, otherwise :class:`GNUTranslations`. The class's constructor must
158-
take a single :term:`file object` argument. If provided, *codeset* will change
159-
the charset used to encode translated strings in the
160-
:meth:`~NullTranslations.lgettext` and :meth:`~NullTranslations.lngettext`
161-
methods.
158+
take a single :term:`file object` argument.
162159

163160
If multiple files are found, later files are used as fallbacks for earlier ones.
164161
To allow setting the fallback, :func:`copy.copy` is used to clone each
@@ -177,19 +174,19 @@ install themselves in the built-in namespace as the function :func:`_`.
177174

178175
.. function:: install(domain, localedir=None, *, names=None)
179176

180-
This installs the function :func:`_` in Python's builtins namespace, based on
177+
This installs the function :func:`!_` in Python's builtins namespace, based on
181178
*domain* and *localedir* which are passed to the function :func:`translation`.
182179

183180
For the *names* parameter, please see the description of the translation
184181
object's :meth:`~NullTranslations.install` method.
185182

186183
As seen below, you usually mark the strings in your application that are
187-
candidates for translation, by wrapping them in a call to the :func:`_`
184+
candidates for translation, by wrapping them in a call to the :func:`!_`
188185
function, like this::
189186

190187
print(_('This string will be translated.'))
191188

192-
For convenience, you want the :func:`_` function to be installed in Python's
189+
For convenience, you want the :func:`!_` function to be installed in Python's
193190
builtins namespace, so it is easily accessible in all modules of your
194191
application.
195192

@@ -276,20 +273,20 @@ are the methods of :class:`!NullTranslations`:
276273

277274
If the *names* parameter is given, it must be a sequence containing the
278275
names of functions you want to install in the builtins namespace in
279-
addition to :func:`_`. Supported names are ``'gettext'``, ``'ngettext'``,
280-
``'pgettext'``, ``'npgettext'``, ``'lgettext'``, and ``'lngettext'``.
276+
addition to :func:`!_`. Supported names are ``'gettext'``, ``'ngettext'``,
277+
``'pgettext'``, and ``'npgettext'``.
281278

282279
Note that this is only one way, albeit the most convenient way, to make
283-
the :func:`_` function available to your application. Because it affects
280+
the :func:`!_` function available to your application. Because it affects
284281
the entire application globally, and specifically the built-in namespace,
285-
localized modules should never install :func:`_`. Instead, they should use
286-
this code to make :func:`_` available to their module::
282+
localized modules should never install :func:`!_`. Instead, they should use
283+
this code to make :func:`!_` available to their module::
287284

288285
import gettext
289286
t = gettext.translation('mymodule', ...)
290287
_ = t.gettext
291288

292-
This puts :func:`_` only in the module's global namespace and so only
289+
This puts :func:`!_` only in the module's global namespace and so only
293290
affects calls within this module.
294291

295292
.. versionchanged:: 3.8
@@ -314,7 +311,7 @@ initialize the "protected" :attr:`_charset` instance variable, defaulting to
314311
ids and message strings read from the catalog are converted to Unicode using
315312
this encoding, else ASCII is assumed.
316313

317-
Since message ids are read as Unicode strings too, all :meth:`*gettext` methods
314+
Since message ids are read as Unicode strings too, all ``*gettext()`` methods
318315
will assume message ids as Unicode strings, not byte strings.
319316

320317
The entire set of key/value pairs are placed into a dictionary and set as the
@@ -404,7 +401,7 @@ version has a slightly different API. Its documented usage was::
404401
_ = cat.gettext
405402
print(_('hello world'))
406403

407-
For compatibility with this older module, the function :func:`Catalog` is an
404+
For compatibility with this older module, the function :func:`!Catalog` is an
408405
alias for the :func:`translation` function described above.
409406

410407
One difference between this module and Henstridge's: his catalog objects
@@ -432,7 +429,7 @@ take the following steps:
432429

433430
In order to prepare your code for I18N, you need to look at all the strings in
434431
your files. Any string that needs to be translated should be marked by wrapping
435-
it in ``_('...')`` --- that is, a call to the function :func:`_`. For example::
432+
it in ``_('...')`` --- that is, a call to the function :func:`_ <gettext>`. For example::
436433

437434
filename = 'mylog.txt'
438435
message = _('writing a log message')
@@ -504,7 +501,7 @@ module::
504501
Localizing your application
505502
^^^^^^^^^^^^^^^^^^^^^^^^^^^
506503

507-
If you are localizing your application, you can install the :func:`_` function
504+
If you are localizing your application, you can install the :func:`!_` function
508505
globally into the built-in namespace, usually in the main driver file of your
509506
application. This will let all your application-specific files just use
510507
``_('...')`` without having to explicitly install it in each file.
@@ -581,13 +578,13 @@ Here is one way you can handle this situation::
581578
for a in animals:
582579
print(_(a))
583580

584-
This works because the dummy definition of :func:`_` simply returns the string
581+
This works because the dummy definition of :func:`!_` simply returns the string
585582
unchanged. And this dummy definition will temporarily override any definition
586-
of :func:`_` in the built-in namespace (until the :keyword:`del` command). Take
587-
care, though if you have a previous definition of :func:`_` in the local
583+
of :func:`!_` in the built-in namespace (until the :keyword:`del` command). Take
584+
care, though if you have a previous definition of :func:`!_` in the local
588585
namespace.
589586

590-
Note that the second use of :func:`_` will not identify "a" as being
587+
Note that the second use of :func:`!_` will not identify "a" as being
591588
translatable to the :program:`gettext` program, because the parameter
592589
is not a string literal.
593590

@@ -606,13 +603,13 @@ Another way to handle this is with the following example::
606603
print(_(a))
607604

608605
In this case, you are marking translatable strings with the function
609-
:func:`N_`, which won't conflict with any definition of :func:`_`.
606+
:func:`!N_`, which won't conflict with any definition of :func:`!_`.
610607
However, you will need to teach your message extraction program to
611-
look for translatable strings marked with :func:`N_`. :program:`xgettext`,
608+
look for translatable strings marked with :func:`!N_`. :program:`xgettext`,
612609
:program:`pygettext`, ``pybabel extract``, and :program:`xpot` all
613610
support this through the use of the :option:`!-k` command-line switch.
614-
The choice of :func:`N_` here is totally arbitrary; it could have just
615-
as easily been :func:`MarkThisStringForTranslation`.
611+
The choice of :func:`!N_` here is totally arbitrary; it could have just
612+
as easily been :func:`!MarkThisStringForTranslation`.
616613

617614

618615
Acknowledgements

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)