Skip to content

Commit bc68b9a

Browse files
committed
Merge branch 'main' into gh-110481-inter-thread-queue
2 parents f00252a + b6228b5 commit bc68b9a

File tree

289 files changed

+4530
-1823
lines changed

Some content is hidden

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

289 files changed

+4530
-1823
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ jobs:
250250
strategy:
251251
fail-fast: false
252252
matrix:
253-
openssl_ver: [1.1.1w, 3.0.11, 3.1.3]
253+
openssl_ver: [1.1.1w, 3.0.13, 3.1.5, 3.2.1]
254254
env:
255255
OPENSSL_VER: ${{ matrix.openssl_ver }}
256256
MULTISSL_DIR: ${{ github.workspace }}/multissl
@@ -304,7 +304,7 @@ jobs:
304304
needs: check_source
305305
if: needs.check_source.outputs.run_tests == 'true' && needs.check_source.outputs.run_hypothesis == 'true'
306306
env:
307-
OPENSSL_VER: 3.0.11
307+
OPENSSL_VER: 3.0.13
308308
PYTHONSTRICTEXTENSIONBUILD: 1
309309
steps:
310310
- uses: actions/checkout@v4
@@ -415,7 +415,7 @@ jobs:
415415
needs: check_source
416416
if: needs.check_source.outputs.run_tests == 'true'
417417
env:
418-
OPENSSL_VER: 3.0.11
418+
OPENSSL_VER: 3.0.13
419419
PYTHONSTRICTEXTENSIONBUILD: 1
420420
ASAN_OPTIONS: detect_leaks=0:allocator_may_return_null=1:handle_segv=0
421421
steps:

.github/workflows/jit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
jit:
1919
name: ${{ matrix.target }} (${{ matrix.debug && 'Debug' || 'Release' }})
2020
runs-on: ${{ matrix.runner }}
21+
timeout-minutes: 60
2122
strategy:
2223
fail-fast: false
2324
matrix:

.github/workflows/reusable-ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
timeout-minutes: 60
1515
runs-on: ubuntu-20.04
1616
env:
17-
OPENSSL_VER: 3.0.11
17+
OPENSSL_VER: 3.0.13
1818
PYTHONSTRICTEXTENSIONBUILD: 1
1919
steps:
2020
- uses: actions/checkout@v4

.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.1.7
3+
rev: v0.2.0
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/

Doc/c-api/dict.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@ Dictionary Objects
174174
.. versionadded:: 3.4
175175
176176
177+
.. c:function:: int PyDict_SetDefaultRef(PyObject *p, PyObject *key, PyObject *default_value, PyObject **result)
178+
179+
Inserts *default_value* into the dictionary *p* with a key of *key* if the
180+
key is not already present in the dictionary. If *result* is not ``NULL``,
181+
then *\*result* is set to a :term:`strong reference` to either
182+
*default_value*, if the key was not present, or the existing value, if *key*
183+
was already present in the dictionary.
184+
Returns ``1`` if the key was present and *default_value* was not inserted,
185+
or ``0`` if the key was not present and *default_value* was inserted.
186+
On failure, returns ``-1``, sets an exception, and sets ``*result``
187+
to ``NULL``.
188+
189+
For clarity: if you have a strong reference to *default_value* before
190+
calling this function, then after it returns, you hold a strong reference
191+
to both *default_value* and *\*result* (if it's not ``NULL``).
192+
These may refer to the same object: in that case you hold two separate
193+
references to it.
194+
.. versionadded:: 3.13
195+
196+
177197
.. c:function:: int PyDict_Pop(PyObject *p, PyObject *key, PyObject **result)
178198
179199
Remove *key* from dictionary *p* and optionally return the removed value.

Doc/c-api/import.rst

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,8 @@ Importing Modules
1313
single: __all__ (package variable)
1414
single: modules (in module sys)
1515
16-
This is a simplified interface to :c:func:`PyImport_ImportModuleEx` below,
17-
leaving the *globals* and *locals* arguments set to ``NULL`` and *level* set
18-
to 0. When the *name*
19-
argument contains a dot (when it specifies a submodule of a package), the
20-
*fromlist* argument is set to the list ``['*']`` so that the return value is the
21-
named module rather than the top-level package containing it as would otherwise
22-
be the case. (Unfortunately, this has an additional side effect when *name* in
23-
fact specifies a subpackage instead of a submodule: the submodules specified in
24-
the package's ``__all__`` variable are loaded.) Return a new reference to the
25-
imported module, or ``NULL`` with an exception set on failure. A failing
26-
import of a module doesn't leave the module in :data:`sys.modules`.
27-
28-
This function always uses absolute imports.
29-
16+
This is a wrapper around :c:func:`PyImport_Import()` which takes a
17+
:c:expr:`const char *` as an argument instead of a :c:expr:`PyObject *`.
3018
3119
.. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
3220

Doc/c-api/list.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,21 @@ List Objects
5656
Similar to :c:func:`PyList_Size`, but without error checking.
5757
5858
59-
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
59+
.. c:function:: PyObject* PyList_GetItemRef(PyObject *list, Py_ssize_t index)
6060
6161
Return the object at position *index* in the list pointed to by *list*. The
6262
position must be non-negative; indexing from the end of the list is not
63-
supported. If *index* is out of bounds (<0 or >=len(list)),
63+
supported. If *index* is out of bounds (:code:`<0 or >=len(list)`),
6464
return ``NULL`` and set an :exc:`IndexError` exception.
6565
66+
.. versionadded:: 3.13
67+
68+
69+
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
70+
71+
Like :c:func:`PyList_GetItemRef`, but returns a
72+
:term:`borrowed reference` instead of a :term:`strong reference`.
73+
6674
6775
.. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
6876

Doc/data/refcounts.dat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,10 @@ PyList_GetItem:PyObject*::0:
11331133
PyList_GetItem:PyObject*:list:0:
11341134
PyList_GetItem:Py_ssize_t:index::
11351135

1136+
PyList_GetItemRef:PyObject*::+1:
1137+
PyList_GetItemRef:PyObject*:list:0:
1138+
PyList_GetItemRef:Py_ssize_t:index::
1139+
11361140
PyList_GetSlice:PyObject*::+1:
11371141
PyList_GetSlice:PyObject*:list:0:
11381142
PyList_GetSlice:Py_ssize_t:low::

Doc/data/stable_abi.dat

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

Doc/faq/library.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -405,22 +405,37 @@ lists. When in doubt, use a mutex!
405405
Can't we get rid of the Global Interpreter Lock?
406406
------------------------------------------------
407407
408-
.. XXX link to dbeazley's talk about GIL?
409-
410408
The :term:`global interpreter lock` (GIL) is often seen as a hindrance to Python's
411409
deployment on high-end multiprocessor server machines, because a multi-threaded
412410
Python program effectively only uses one CPU, due to the insistence that
413411
(almost) all Python code can only run while the GIL is held.
414412
415-
Back in the days of Python 1.5, Greg Stein actually implemented a comprehensive
413+
With the approval of :pep:`703` work is now underway to remove the GIL from the
414+
CPython implementation of Python. Initially it will be implemented as an
415+
optional compiler flag when building the interpreter, and so separate
416+
builds will be available with and without the GIL. Long-term, the hope is
417+
to settle on a single build, once the performance implications of removing the
418+
GIL are fully understood. Python 3.13 is likely to be the first release
419+
containing this work, although it may not be completely functional in this
420+
release.
421+
422+
The current work to remove the GIL is based on a
423+
`fork of Python 3.9 with the GIL removed <https://github.com/colesbury/nogil>`_
424+
by Sam Gross.
425+
Prior to that,
426+
in the days of Python 1.5, Greg Stein actually implemented a comprehensive
416427
patch set (the "free threading" patches) that removed the GIL and replaced it
417-
with fine-grained locking. Adam Olsen recently did a similar experiment
428+
with fine-grained locking. Adam Olsen did a similar experiment
418429
in his `python-safethread <https://code.google.com/archive/p/python-safethread>`_
419-
project. Unfortunately, both experiments exhibited a sharp drop in single-thread
430+
project. Unfortunately, both of these earlier experiments exhibited a sharp
431+
drop in single-thread
420432
performance (at least 30% slower), due to the amount of fine-grained locking
421-
necessary to compensate for the removal of the GIL.
433+
necessary to compensate for the removal of the GIL. The Python 3.9 fork
434+
is the first attempt at removing the GIL with an acceptable performance
435+
impact.
422436
423-
This doesn't mean that you can't make good use of Python on multi-CPU machines!
437+
The presence of the GIL in current Python releases
438+
doesn't mean that you can't make good use of Python on multi-CPU machines!
424439
You just have to be creative with dividing the work up between multiple
425440
*processes* rather than multiple *threads*. The
426441
:class:`~concurrent.futures.ProcessPoolExecutor` class in the new
@@ -434,22 +449,13 @@ thread of execution is in the C code and allow other threads to get some work
434449
done. Some standard library modules such as :mod:`zlib` and :mod:`hashlib`
435450
already do this.
436451
437-
It has been suggested that the GIL should be a per-interpreter-state lock rather
438-
than truly global; interpreters then wouldn't be able to share objects.
439-
Unfortunately, this isn't likely to happen either. It would be a tremendous
440-
amount of work, because many object implementations currently have global state.
441-
For example, small integers and short strings are cached; these caches would
442-
have to be moved to the interpreter state. Other object types have their own
443-
free list; these free lists would have to be moved to the interpreter state.
444-
And so on.
445-
446-
And I doubt that it can even be done in finite time, because the same problem
447-
exists for 3rd party extensions. It is likely that 3rd party extensions are
448-
being written at a faster rate than you can convert them to store all their
449-
global state in the interpreter state.
450-
451-
And finally, once you have multiple interpreters not sharing any state, what
452-
have you gained over running each interpreter in a separate process?
452+
An alternative approach to reducing the impact of the GIL is
453+
to make the GIL a per-interpreter-state lock rather than truly global.
454+
This was :ref:`first implemented in Python 3.12 <whatsnew312-pep684>` and is
455+
available in the C API. A Python interface to it is expected in Python 3.13.
456+
The main limitation to it at the moment is likely to be 3rd party extension
457+
modules, since these must be written with multiple interpreters in mind in
458+
order to be usable, so many older extension modules will not be usable.
453459
454460
455461
Input and Output

Doc/glossary.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Glossary
341341
docstring
342342
A string literal which appears as the first expression in a class,
343343
function or module. While ignored when the suite is executed, it is
344-
recognized by the compiler and put into the :attr:`__doc__` attribute
344+
recognized by the compiler and put into the :attr:`!__doc__` attribute
345345
of the enclosing class, function or module. Since it is available via
346346
introspection, it is the canonical place for documentation of the
347347
object.
@@ -1104,10 +1104,12 @@ Glossary
11041104
The :class:`collections.abc.Sequence` abstract base class
11051105
defines a much richer interface that goes beyond just
11061106
:meth:`~object.__getitem__` and :meth:`~object.__len__`, adding
1107-
:meth:`count`, :meth:`index`, :meth:`~object.__contains__`, and
1107+
:meth:`!count`, :meth:`!index`, :meth:`~object.__contains__`, and
11081108
:meth:`~object.__reversed__`. Types that implement this expanded
11091109
interface can be registered explicitly using
1110-
:func:`~abc.ABCMeta.register`.
1110+
:func:`~abc.ABCMeta.register`. For more documentation on sequence
1111+
methods generally, see
1112+
:ref:`Common Sequence Operations <typesseq-common>`.
11111113

11121114
set comprehension
11131115
A compact way to process all or part of the elements in an iterable and

Doc/howto/enum.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,30 @@ the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
497497
>>> Creature.DOG
498498
<Creature.DOG: size='medium', legs=4>
499499

500-
Use the :func:`!dataclass` argument ``repr=False``
500+
Use the :func:`~dataclasses.dataclass` argument ``repr=False``
501501
to use the standard :func:`repr`.
502502

503503
.. versionchanged:: 3.12
504504
Only the dataclass fields are shown in the value area, not the dataclass'
505505
name.
506506

507+
.. note::
508+
509+
Adding :func:`~dataclasses.dataclass` decorator to :class:`Enum`
510+
and its subclasses is not supported. It will not raise any errors,
511+
but it will produce very strange results at runtime, such as members
512+
being equal to each other::
513+
514+
>>> @dataclass # don't do this: it does not make any sense
515+
... class Color(Enum):
516+
... RED = 1
517+
... BLUE = 2
518+
...
519+
>>> Color.RED is Color.BLUE
520+
False
521+
>>> Color.RED == Color.BLUE # problem is here: they should not be equal
522+
True
523+
507524

508525
Pickling
509526
--------

Doc/howto/logging-cookbook.rst

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,30 +1933,28 @@ This dictionary is passed to :func:`~config.dictConfig` to put the configuration
19331933

19341934
LOGGING = {
19351935
'version': 1,
1936-
'disable_existing_loggers': True,
1936+
'disable_existing_loggers': False,
19371937
'formatters': {
19381938
'verbose': {
1939-
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
1939+
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
1940+
'style': '{',
19401941
},
19411942
'simple': {
1942-
'format': '%(levelname)s %(message)s'
1943+
'format': '{levelname} {message}',
1944+
'style': '{',
19431945
},
19441946
},
19451947
'filters': {
19461948
'special': {
19471949
'()': 'project.logging.SpecialFilter',
19481950
'foo': 'bar',
1949-
}
1951+
},
19501952
},
19511953
'handlers': {
1952-
'null': {
1953-
'level':'DEBUG',
1954-
'class':'django.utils.log.NullHandler',
1955-
},
1956-
'console':{
1957-
'level':'DEBUG',
1958-
'class':'logging.StreamHandler',
1959-
'formatter': 'simple'
1954+
'console': {
1955+
'level': 'INFO',
1956+
'class': 'logging.StreamHandler',
1957+
'formatter': 'simple',
19601958
},
19611959
'mail_admins': {
19621960
'level': 'ERROR',
@@ -1966,9 +1964,8 @@ This dictionary is passed to :func:`~config.dictConfig` to put the configuration
19661964
},
19671965
'loggers': {
19681966
'django': {
1969-
'handlers':['null'],
1967+
'handlers': ['console'],
19701968
'propagate': True,
1971-
'level':'INFO',
19721969
},
19731970
'django.request': {
19741971
'handlers': ['mail_admins'],

0 commit comments

Comments
 (0)