Skip to content

Commit cf78d2b

Browse files
committed
Merge branch 'main' into entry-frame
2 parents 4d5e9a5 + c09fa75 commit cf78d2b

Some content is hidden

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

52 files changed

+2215
-1180
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# https://git-scm.com/docs/gitignore#_pattern_format
66

77
# asyncio
8-
**/*asyncio* @1st1 @asvetlov
8+
**/*asyncio* @1st1 @asvetlov @gvanrossum
99

1010
# Core
1111
**/*context* @1st1
12-
**/*genobject* @1st1 @markshannon
12+
**/*genobject* @markshannon
1313
**/*hamt* @1st1
1414
Objects/set* @rhettinger
1515
Objects/dict* @methane @markshannon

Doc/c-api/init.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,18 @@ Python-level trace functions in previous versions.
17741774
17751775
The caller must hold the :term:`GIL`.
17761776
1777+
.. c:function:: void PyEval_SetProfileAllThreads(Py_tracefunc func, PyObject *obj)
1778+
1779+
Like :c:func:`PyEval_SetProfile` but sets the profile function in all running threads
1780+
belonging to the current interpreter instead of the setting it only on the current thread.
1781+
1782+
The caller must hold the :term:`GIL`.
1783+
1784+
As :c:func:`PyEval_SetProfile`, this function ignores any exceptions raised while
1785+
setting the profile functions in all threads.
1786+
1787+
.. versionadded:: 3.12
1788+
17771789
17781790
.. c:function:: void PyEval_SetTrace(Py_tracefunc func, PyObject *obj)
17791791
@@ -1788,6 +1800,18 @@ Python-level trace functions in previous versions.
17881800
17891801
The caller must hold the :term:`GIL`.
17901802
1803+
.. c:function:: void PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *obj)
1804+
1805+
Like :c:func:`PyEval_SetTrace` but sets the tracing function in all running threads
1806+
belonging to the current interpreter instead of the setting it only on the current thread.
1807+
1808+
The caller must hold the :term:`GIL`.
1809+
1810+
As :c:func:`PyEval_SetTrace`, this function ignores any exceptions raised while
1811+
setting the trace functions in all threads.
1812+
1813+
.. versionadded:: 3.12
1814+
17911815
17921816
.. _advanced-debugging:
17931817

Doc/data/refcounts.dat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,10 +796,18 @@ PyEval_SetProfile:void:::
796796
PyEval_SetProfile:Py_tracefunc:func::
797797
PyEval_SetProfile:PyObject*:obj:+1:
798798

799+
PyEval_SetProfileAllThreads:void:::
800+
PyEval_SetProfileAllThreads:Py_tracefunc:func::
801+
PyEval_SetProfileAllThreads:PyObject*:obj:+1:
802+
799803
PyEval_SetTrace:void:::
800804
PyEval_SetTrace:Py_tracefunc:func::
801805
PyEval_SetTrace:PyObject*:obj:+1:
802806

807+
PyEval_SetTraceAllThreads:void:::
808+
PyEval_SetTraceAllThreads:Py_tracefunc:func::
809+
PyEval_SetTraceAllThreads:PyObject*:obj:+1:
810+
803811
PyEval_EvalCode:PyObject*::+1:
804812
PyEval_EvalCode:PyObject*:co:0:
805813
PyEval_EvalCode:PyObject*:globals:0:

Doc/library/bisect.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ records in a table::
216216
... Movie('Aliens', 1986, 'Scott')
217217
... ]
218218

219-
>>> # Find the first movie released on or after 1960
219+
>>> # Find the first movie released after 1960
220220
>>> by_year = attrgetter('released')
221221
>>> movies.sort(key=by_year)
222222
>>> movies[bisect(movies, 1960, key=by_year)]

Doc/library/functions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ are always available. They are listed here in alphabetical order.
164164
:func:`sys.breakpointhook` can be set to some other function and
165165
:func:`breakpoint` will automatically call that, allowing you to drop into
166166
the debugger of choice.
167+
If :func:`sys.breakpointhook` is not available to be called, this function will
168+
raise :exc:`RuntimeError`.
167169

168170
.. audit-event:: builtins.breakpoint breakpointhook breakpoint
169171

Doc/library/json.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
**Source code:** :source:`Lib/json/__init__.py`
1111

12+
.. testsetup:: *
13+
14+
import json
15+
from json import AttrDict
16+
1217
--------------
1318

1419
`JSON (JavaScript Object Notation) <https://json.org>`_, specified by
@@ -532,6 +537,44 @@ Exceptions
532537

533538
.. versionadded:: 3.5
534539

540+
.. class:: AttrDict(**kwargs)
541+
AttrDict(mapping, **kwargs)
542+
AttrDict(iterable, **kwargs)
543+
544+
Subclass of :class:`dict` object that also supports attribute style dotted access.
545+
546+
This class is intended for use with the :attr:`object_hook` in
547+
:func:`json.load` and :func:`json.loads`::
548+
549+
.. doctest::
550+
551+
>>> json_string = '{"mercury": 88, "venus": 225, "earth": 365, "mars": 687}'
552+
>>> orbital_period = json.loads(json_string, object_hook=AttrDict)
553+
>>> orbital_period['earth'] # Dict style lookup
554+
365
555+
>>> orbital_period.earth # Attribute style lookup
556+
365
557+
>>> orbital_period.keys() # All dict methods are present
558+
dict_keys(['mercury', 'venus', 'earth', 'mars'])
559+
560+
Attribute style access only works for keys that are valid attribute
561+
names. In contrast, dictionary style access works for all keys. For
562+
example, ``d.two words`` contains a space and is not syntactically
563+
valid Python, so ``d["two words"]`` should be used instead.
564+
565+
If a key has the same name as a dictionary method, then a dictionary
566+
lookup finds the key and an attribute lookup finds the method:
567+
568+
.. doctest::
569+
570+
>>> d = AttrDict(items=50)
571+
>>> d['items'] # Lookup the key
572+
50
573+
>>> d.items() # Call the method
574+
dict_items([('items', 50)])
575+
576+
.. versionadded:: 3.12
577+
535578

536579
Standard Compliance and Interoperability
537580
----------------------------------------

Doc/library/logging.handlers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,12 @@ supports sending logging messages to a remote or local Unix syslog.
629629
application needs to run on several platforms). On Windows, you pretty
630630
much have to use the UDP option.
631631

632+
.. note:: On macOS 12.x (Monterey), Apple has changed the behaviour of their
633+
syslog daemon - it no longer listens on a domain socket. Therefore, you cannot
634+
expect :class:`SysLogHandler` to work on this system.
635+
636+
See :gh:`91070` for more information.
637+
632638
.. versionchanged:: 3.2
633639
*socktype* was added.
634640

Doc/library/sqlite3.rst

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,41 @@ and you can let the :mod:`!sqlite3` module convert SQLite types to
15431543
Python types via :ref:`converters <sqlite3-converters>`.
15441544

15451545

1546+
.. _sqlite3-default-converters:
1547+
1548+
Default adapters and converters (deprecated)
1549+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1550+
1551+
.. note::
1552+
1553+
The default adapters and converters are deprecated as of Python 3.12.
1554+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1555+
and tailor them to your needs.
1556+
1557+
The deprecated default adapters and converters consist of:
1558+
1559+
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1560+
`ISO 8601`_ format.
1561+
* An adapter for :class:`datetime.datetime` objects to strings in
1562+
ISO 8601 format.
1563+
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1564+
:class:`datetime.date` objects.
1565+
* A converter for declared "timestamp" types to
1566+
:class:`datetime.datetime` objects.
1567+
Fractional parts will be truncated to 6 digits (microsecond precision).
1568+
1569+
.. note::
1570+
1571+
The default "timestamp" converter ignores UTC offsets in the database and
1572+
always returns a naive :class:`datetime.datetime` object. To preserve UTC
1573+
offsets in timestamps, either leave converters disabled, or register an
1574+
offset-aware converter with :func:`register_converter`.
1575+
1576+
.. deprecated:: 3.12
1577+
1578+
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1579+
1580+
15461581
.. _sqlite3-cli:
15471582

15481583
Command-line interface
@@ -1602,8 +1637,8 @@ both styles:
16021637

16031638
.. _sqlite3-adapters:
16041639

1605-
Using adapters to store custom Python types in SQLite databases
1606-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1640+
How to adapt custom Python types to SQLite values
1641+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16071642

16081643
SQLite supports only a limited set of data types natively.
16091644
To store custom Python types in SQLite databases, *adapt* them to one of the
@@ -1620,8 +1655,8 @@ registering custom adapter functions.
16201655

16211656
.. _sqlite3-conform:
16221657

1623-
Letting your object adapt itself
1624-
""""""""""""""""""""""""""""""""
1658+
How to write adaptable objects
1659+
""""""""""""""""""""""""""""""
16251660

16261661
Suppose we have a :class:`!Point` class that represents a pair of coordinates,
16271662
``x`` and ``y``, in a Cartesian coordinate system.
@@ -1634,8 +1669,8 @@ The object passed to *protocol* will be of type :class:`PrepareProtocol`.
16341669
.. literalinclude:: ../includes/sqlite3/adapter_point_1.py
16351670

16361671

1637-
Registering an adapter callable
1638-
"""""""""""""""""""""""""""""""
1672+
How to register adapter callables
1673+
"""""""""""""""""""""""""""""""""
16391674

16401675
The other possibility is to create a function that converts the Python object
16411676
to an SQLite-compatible type.
@@ -1646,8 +1681,8 @@ This function can then be registered using :func:`register_adapter`.
16461681

16471682
.. _sqlite3-converters:
16481683

1649-
Converting SQLite values to custom Python types
1650-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1684+
How to convert SQLite values to custom Python types
1685+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16511686

16521687
Writing an adapter lets you convert *from* custom Python types *to* SQLite
16531688
values.
@@ -1686,41 +1721,6 @@ The following example illustrates the implicit and explicit approaches:
16861721
.. literalinclude:: ../includes/sqlite3/converter_point.py
16871722

16881723

1689-
.. _sqlite3-default-converters:
1690-
1691-
Default adapters and converters (deprecated)
1692-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1693-
1694-
.. note::
1695-
1696-
The default adapters and converters are deprecated as of Python 3.12.
1697-
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1698-
and tailor them to your needs.
1699-
1700-
The deprecated default adapters and converters consist of:
1701-
1702-
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1703-
`ISO 8601`_ format.
1704-
* An adapter for :class:`datetime.datetime` objects to strings in
1705-
ISO 8601 format.
1706-
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1707-
:class:`datetime.date` objects.
1708-
* A converter for declared "timestamp" types to
1709-
:class:`datetime.datetime` objects.
1710-
Fractional parts will be truncated to 6 digits (microsecond precision).
1711-
1712-
.. note::
1713-
1714-
The default "timestamp" converter ignores UTC offsets in the database and
1715-
always returns a naive :class:`datetime.datetime` object. To preserve UTC
1716-
offsets in timestamps, either leave converters disabled, or register an
1717-
offset-aware converter with :func:`register_converter`.
1718-
1719-
.. deprecated:: 3.12
1720-
1721-
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1722-
1723-
17241724
.. _sqlite3-adapter-converter-recipes:
17251725

17261726
Adapter and converter recipes
@@ -1768,8 +1768,8 @@ This section shows recipes for common adapters and converters.
17681768
17691769
.. _sqlite3-connection-shortcuts:
17701770

1771-
Using connection shortcut methods
1772-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1771+
How to use connection shortcut methods
1772+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17731773

17741774
Using the :meth:`~Connection.execute`,
17751775
:meth:`~Connection.executemany`, and :meth:`~Connection.executescript`
@@ -1785,7 +1785,7 @@ directly using only a single call on the :class:`Connection` object.
17851785

17861786
.. _sqlite3-connection-context-manager:
17871787

1788-
Using the connection as a context manager
1788+
How to use the connection context manager
17891789
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17901790

17911791
A :class:`Connection` object can be used as a context manager that
@@ -1810,8 +1810,8 @@ the context manager is a no-op.
18101810

18111811
.. _sqlite3-uri-tricks:
18121812

1813-
Working with SQLite URIs
1814-
^^^^^^^^^^^^^^^^^^^^^^^^
1813+
How to work with SQLite URIs
1814+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18151815

18161816
Some useful URI tricks include:
18171817

Doc/library/threading.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ This module defines the following functions:
158158
The *func* will be passed to :func:`sys.settrace` for each thread, before its
159159
:meth:`~Thread.run` method is called.
160160

161+
.. function:: settrace_all_threads(func)
162+
163+
Set a trace function for all threads started from the :mod:`threading` module
164+
and all Python threads that are currently executing.
165+
166+
The *func* will be passed to :func:`sys.settrace` for each thread, before its
167+
:meth:`~Thread.run` method is called.
168+
169+
.. versionadded:: 3.12
161170

162171
.. function:: gettrace()
163172

@@ -178,6 +187,15 @@ This module defines the following functions:
178187
The *func* will be passed to :func:`sys.setprofile` for each thread, before its
179188
:meth:`~Thread.run` method is called.
180189

190+
.. function:: setprofile_all_threads(func)
191+
192+
Set a profile function for all threads started from the :mod:`threading` module
193+
and all Python threads that are currently executing.
194+
195+
The *func* will be passed to :func:`sys.setprofile` for each thread, before its
196+
:meth:`~Thread.run` method is called.
197+
198+
.. versionadded:: 3.12
181199

182200
.. function:: getprofile()
183201

Include/cpython/ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#endif
44

55
PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
6+
PyAPI_FUNC(void) PyEval_SetProfileAllThreads(Py_tracefunc, PyObject *);
67
PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
78
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
9+
PyAPI_FUNC(void) PyEval_SetTraceAllThreads(Py_tracefunc, PyObject *);
810
PyAPI_FUNC(int) _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
911

1012
/* Helper to look up a builtin object */

Include/internal/pycore_ceval.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ extern struct _PyInterpreterFrame* _PyEval_GetFrame(void);
133133

134134
extern PyObject* _Py_MakeCoro(PyFunctionObject *func);
135135

136+
extern int _Py_HandlePending(PyThreadState *tstate);
137+
138+
136139
#ifdef __cplusplus
137140
}
138141
#endif

Include/internal/pycore_compile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ extern int _PyAST_Optimize(
3838
struct _arena *arena,
3939
_PyASTOptimizeState *state);
4040

41+
/* Access compiler internals for unit testing */
42+
PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
43+
PyObject *instructions,
44+
PyObject *consts);
45+
4146
#ifdef __cplusplus
4247
}
4348
#endif

0 commit comments

Comments
 (0)