Skip to content

Commit 8fc75f0

Browse files
committed
Merge branch 'main' into gh-148874/with-signal-exit-skip
2 parents 40fc50c + 3a1df78 commit 8fc75f0

192 files changed

Lines changed: 7602 additions & 3426 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.

.github/workflows/posix-deps-apt.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ apt-get -yq --no-install-recommends install \
2626
xvfb \
2727
zlib1g-dev
2828

29-
# Workaround missing libmpdec-dev on ubuntu 24.04:
30-
# https://launchpad.net/~ondrej/+archive/ubuntu/php
31-
# https://deb.sury.org/
32-
sudo add-apt-repository ppa:ondrej/php
33-
apt-get update
34-
apt-get -yq --no-install-recommends install libmpdec-dev
29+
# Workaround missing libmpdec-dev on ubuntu 24.04 by building mpdecimal
30+
# from source. ppa:ondrej/php (launchpad.net) are unreliable
31+
# (https://status.canonical.com) so fetch the tarball directly
32+
# from the upstream host.
33+
# https://www.bytereef.org/mpdecimal/
34+
MPDECIMAL_VERSION=4.0.1
35+
curl -fsSL "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-${MPDECIMAL_VERSION}.tar.gz" \
36+
| tar -xz -C /tmp
37+
(cd "/tmp/mpdecimal-${MPDECIMAL_VERSION}" \
38+
&& ./configure --prefix=/usr/local \
39+
&& make -j"$(nproc)" \
40+
&& make install)
41+
ldconfig

Doc/c-api/perfmaps.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Note that holding an :term:`attached thread state` is not required for these API
3131
or ``-2`` on failure to create a lock. Check ``errno`` for more information
3232
about the cause of a failure.
3333

34-
.. c:function:: int PyUnstable_WritePerfMapEntry(const void *code_addr, unsigned int code_size, const char *entry_name)
34+
.. c:function:: int PyUnstable_WritePerfMapEntry(const void *code_addr, size_t code_size, const char *entry_name)
3535
3636
Write one single entry to the ``/tmp/perf-$pid.map`` file. This function is
3737
thread safe. Here is what an example entry looks like::

Doc/deprecations/pending-removal-in-3.20.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ Pending removal in Python 3.20
3838
- :mod:`zlib`
3939

4040
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
41+
42+
* :mod:`ast`:
43+
44+
* Creating instances of abstract AST nodes (such as :class:`ast.AST`
45+
or :class:`!ast.expr`) is deprecated and will raise an error in Python 3.20.

Doc/faq/programming.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ correctly using identity tests:
19241924

19251925
.. code-block:: python
19261926
1927-
_sentinel = object()
1927+
_sentinel = sentinel('_sentinel')
19281928
19291929
def pop(self, key, default=_sentinel):
19301930
if key in self:

Doc/howto/descriptor.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ a pure Python equivalent:
594594

595595
def object_getattribute(obj, name):
596596
"Emulate PyObject_GenericGetAttr() in Objects/object.c"
597-
null = object()
597+
null = sentinel('null')
598598
objtype = type(obj)
599599
cls_var = find_name_in_mro(objtype, name, null)
600600
descr_get = getattr(type(cls_var), '__get__', null)
@@ -1635,12 +1635,12 @@ by member descriptors:
16351635

16361636
.. testcode::
16371637

1638-
null = object()
1638+
null = sentinel('null')
16391639

16401640
class Member:
16411641

16421642
def __init__(self, name, clsname, offset):
1643-
'Emulate PyMemberDef in Include/structmember.h'
1643+
'Emulate PyMemberDef in Include/descrobject.h'
16441644
# Also see descr_new() in Objects/descrobject.c
16451645
self.name = name
16461646
self.clsname = clsname

Doc/howto/perf_profiling.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ Example, using the :mod:`sys` APIs in file :file:`example.py`:
217217
How to obtain the best results
218218
------------------------------
219219

220-
For best results, Python should be compiled with
221-
``CFLAGS="-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"`` as this allows
220+
For best results, keep frame pointers enabled. On supported GCC-compatible
221+
toolchains, CPython builds itself with ``-fno-omit-frame-pointer`` and, when
222+
available, ``-mno-omit-leaf-frame-pointer`` by default. These flags allow
222223
profilers to unwind using only the frame pointer and not on DWARF debug
223224
information. This is because as the code that is interposed to allow ``perf``
224225
support is dynamically generated it doesn't have any DWARF debugging information

Doc/library/ast.rst

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Node classes
4242

4343
.. class:: AST
4444

45-
This is the base of all AST node classes. The actual node classes are
45+
This is the abstract base of all AST node classes. The actual node classes are
4646
derived from the :file:`Parser/Python.asdl` file, which is reproduced
4747
:ref:`above <abstract-grammar>`. They are defined in the :mod:`!_ast` C
4848
module and re-exported in :mod:`!ast`.
@@ -168,6 +168,15 @@ Node classes
168168
arguments that were set as attributes of the AST node, even if they did not
169169
match any of the fields of the AST node. These cases now raise a :exc:`TypeError`.
170170

171+
.. deprecated-removed:: next 3.20
172+
173+
In the :ref:`grammar above <abstract-grammar>`, the AST node classes that
174+
correspond to production rules with variants (aka "sums") are abstract
175+
classes. Previous versions of Python allowed for the creation of direct
176+
instances of these abstract node classes. This behavior is deprecated and
177+
will be removed in Python 3.20.
178+
179+
171180
.. note::
172181
The descriptions of the specific node classes displayed here
173182
were initially adapted from the fantastic `Green Tree
@@ -271,18 +280,25 @@ Root nodes
271280
Literals
272281
^^^^^^^^
273282

274-
.. class:: Constant(value)
283+
.. class:: Constant(value, kind)
275284

276285
A constant value. The ``value`` attribute of the ``Constant`` literal contains the
277286
Python object it represents. The values represented can be instances of :class:`str`,
278287
:class:`bytes`, :class:`int`, :class:`float`, :class:`complex`, and :class:`bool`,
279288
and the constants :data:`None` and :data:`Ellipsis`.
280289

290+
The ``kind`` attribute is an optional string. For string literals with a
291+
``u`` prefix, ``kind`` is set to ``'u'``. For all other
292+
constants, ``kind`` is ``None``.
293+
281294
.. doctest::
282295

283296
>>> print(ast.dump(ast.parse('123', mode='eval'), indent=4))
284297
Expression(
285298
body=Constant(value=123))
299+
>>> print(ast.dump(ast.parse("u'hello'", mode='eval'), indent=4))
300+
Expression(
301+
body=Constant(value='hello', kind='u'))
286302

287303

288304
.. class:: FormattedValue(value, conversion, format_spec)
@@ -2536,6 +2552,20 @@ and classes for traversing abstract syntax trees:
25362552
Added the *color* parameter.
25372553

25382554

2555+
.. function:: compare(a, b, /, *, compare_attributes=False)
2556+
2557+
Recursively compares two ASTs.
2558+
2559+
*compare_attributes* affects whether AST attributes are considered
2560+
in the comparison. If *compare_attributes* is ``False`` (default), then
2561+
attributes are ignored. Otherwise they must all be equal. This
2562+
option is useful to check whether the ASTs are structurally equal but
2563+
differ in whitespace or similar details. Attributes include line numbers
2564+
and column offsets.
2565+
2566+
.. versionadded:: 3.14
2567+
2568+
25392569
.. _ast-compiler-flags:
25402570

25412571
Compiler flags
@@ -2571,20 +2601,6 @@ effects on the compilation of a program:
25712601
.. versionadded:: 3.8
25722602

25732603

2574-
.. function:: compare(a, b, /, *, compare_attributes=False)
2575-
2576-
Recursively compares two ASTs.
2577-
2578-
*compare_attributes* affects whether AST attributes are considered
2579-
in the comparison. If *compare_attributes* is ``False`` (default), then
2580-
attributes are ignored. Otherwise they must all be equal. This
2581-
option is useful to check whether the ASTs are structurally equal but
2582-
differ in whitespace or similar details. Attributes include line numbers
2583-
and column offsets.
2584-
2585-
.. versionadded:: 3.14
2586-
2587-
25882604
.. _ast-cli:
25892605

25902606
Command-line usage

Doc/library/compression.zstd.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,14 @@ Compressing and decompressing data in memory
331331

332332
If *max_length* is non-negative, the method returns at most *max_length*
333333
bytes of decompressed data. If this limit is reached and further
334-
output can be produced, the :attr:`~.needs_input` attribute will
335-
be set to ``False``. In this case, the next call to
334+
output can be produced (or EOF is reached), the :attr:`~.needs_input`
335+
attribute will be set to ``False``. In this case, the next call to
336336
:meth:`~.decompress` may provide *data* as ``b''`` to obtain
337-
more of the output.
337+
more of the output. The full content can thus be read like::
338+
339+
process_output(d.decompress(data, max_length))
340+
while not d.eof and not d.needs_input:
341+
process_output(d.decompress(b"", max_length))
338342

339343
If all of the input data was decompressed and returned (either
340344
because this was less than *max_length* bytes, or because

Doc/library/email.policy.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,26 @@ added matters. To illustrate::
403403
.. attribute:: utf8
404404

405405
If ``False``, follow :rfc:`5322`, supporting non-ASCII characters in
406-
headers by encoding them as "encoded words". If ``True``, follow
407-
:rfc:`6532` and use ``utf-8`` encoding for headers. Messages
406+
headers by encoding them as :rfc:`2047` "encoded words". If ``True``,
407+
follow :rfc:`6532` and use ``utf-8`` encoding for headers. Messages
408408
formatted in this way may be passed to SMTP servers that support
409409
the ``SMTPUTF8`` extension (:rfc:`6531`).
410410

411+
When ``False``, the generator will raise
412+
:exc:`~email.errors.HeaderWriteError` if any header includes non-ASCII
413+
characters in a context where :rfc:`2047` does not permit encoded words.
414+
This particularly applies to mailboxes ("addr-spec") with non-ASCII
415+
characters, which can be created via
416+
:class:`~email.headerregistry.Address`. To use a mailbox with a non-ASCII
417+
domain name with ``utf8=False``, first encode the domain using the
418+
third-party :pypi:`idna` or :pypi:`uts46` module or with
419+
:mod:`encodings.idna`. It is not possible to use a non-ASCII username
420+
("local-part") in a mailbox when ``utf8=False``.
421+
422+
.. versionchanged:: 3.15
423+
Can trigger the raising of :exc:`~email.errors.HeaderWriteError`.
424+
(Earlier versions incorrectly applied :rfc:`2047` in certain contexts,
425+
mostly notably in addr-specs.)
411426

412427
.. attribute:: refold_source
413428

Doc/library/faulthandler.rst

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ tracebacks:
3131
* Each string is limited to 500 characters.
3232
* Only the filename, the function name and the line number are
3333
displayed. (no source code)
34-
* It is limited to 100 frames and 100 threads.
34+
* It is limited to 100 frames per thread, and 100 threads
35+
(configurable via *max_threads*).
3536
* The order is reversed: the most recent call is shown first.
3637

3738
By default, the Python traceback is written to :data:`sys.stderr`. To see
@@ -55,16 +56,20 @@ at Python startup.
5556
Dumping the traceback
5657
---------------------
5758

58-
.. function:: dump_traceback(file=sys.stderr, all_threads=True)
59+
.. function:: dump_traceback(file=sys.stderr, all_threads=True, *, max_threads=100)
5960

6061
Dump the tracebacks of all threads into *file*. If *all_threads* is
61-
``False``, dump only the current thread.
62+
``False``, dump only the current thread. *max_threads* caps the number
63+
of threads dumped.
6264

6365
.. seealso:: :func:`traceback.print_tb`, which can be used to print a traceback object.
6466

6567
.. versionchanged:: 3.5
6668
Added support for passing file descriptor to this function.
6769

70+
.. versionchanged:: next
71+
Added the *max_threads* keyword argument.
72+
6873

6974
Dumping the C stack
7075
-------------------
@@ -100,7 +105,7 @@ instead of the stack, even if the operating system supports dumping stacks.
100105
Fault handler state
101106
-------------------
102107

103-
.. function:: enable(file=sys.stderr, all_threads=True, c_stack=True)
108+
.. function:: enable(file=sys.stderr, all_threads=True, c_stack=True, *, max_threads=100)
104109

105110
Enable the fault handler: install handlers for the :const:`~signal.SIGSEGV`,
106111
:const:`~signal.SIGFPE`, :const:`~signal.SIGABRT`, :const:`~signal.SIGBUS`
@@ -116,6 +121,8 @@ Fault handler state
116121
traceback, unless the system does not support it. See :func:`dump_c_stack` for
117122
more information on compatibility.
118123

124+
*max_threads* caps the number of threads dumped when a fatal signal fires.
125+
119126
.. versionchanged:: 3.5
120127
Added support for passing file descriptor to this function.
121128

@@ -133,6 +140,9 @@ Fault handler state
133140
.. versionchanged:: 3.14
134141
The dump now displays the C stack trace if *c_stack* is true.
135142

143+
.. versionchanged:: next
144+
Added the *max_threads* keyword argument.
145+
136146
.. function:: disable()
137147

138148
Disable the fault handler: uninstall the signal handlers installed by
@@ -146,15 +156,15 @@ Fault handler state
146156
Dumping the tracebacks after a timeout
147157
--------------------------------------
148158

149-
.. function:: dump_traceback_later(timeout, repeat=False, file=sys.stderr, exit=False)
159+
.. function:: dump_traceback_later(timeout, repeat=False, file=sys.stderr, exit=False, *, max_threads=100)
150160

151161
Dump the tracebacks of all threads, after a timeout of *timeout* seconds, or
152162
every *timeout* seconds if *repeat* is ``True``. If *exit* is ``True``, call
153163
:c:func:`!_exit` with status=1 after dumping the tracebacks. (Note
154164
:c:func:`!_exit` exits the process immediately, which means it doesn't do any
155165
cleanup like flushing file buffers.) If the function is called twice, the new
156166
call replaces previous parameters and resets the timeout. The timer has a
157-
sub-second resolution.
167+
sub-second resolution. *max_threads* caps the number of threads dumped.
158168

159169
The *file* must be kept open until the traceback is dumped or
160170
:func:`cancel_dump_traceback_later` is called: see :ref:`issue with file
@@ -168,6 +178,9 @@ Dumping the tracebacks after a timeout
168178
.. versionchanged:: 3.7
169179
This function is now always available.
170180

181+
.. versionchanged:: next
182+
Added the *max_threads* keyword argument.
183+
171184
.. function:: cancel_dump_traceback_later()
172185

173186
Cancel the last call to :func:`dump_traceback_later`.
@@ -176,11 +189,12 @@ Dumping the tracebacks after a timeout
176189
Dumping the traceback on a user signal
177190
--------------------------------------
178191

179-
.. function:: register(signum, file=sys.stderr, all_threads=True, chain=False)
192+
.. function:: register(signum, file=sys.stderr, all_threads=True, chain=False, *, max_threads=100)
180193

181194
Register a user signal: install a handler for the *signum* signal to dump
182195
the traceback of all threads, or of the current thread if *all_threads* is
183196
``False``, into *file*. Call the previous handler if chain is ``True``.
197+
*max_threads* caps the number of threads dumped.
184198

185199
The *file* must be kept open until the signal is unregistered by
186200
:func:`unregister`: see :ref:`issue with file descriptors <faulthandler-fd>`.
@@ -190,6 +204,9 @@ Dumping the traceback on a user signal
190204
.. versionchanged:: 3.5
191205
Added support for passing file descriptor to this function.
192206

207+
.. versionchanged:: next
208+
Added the *max_threads* keyword argument.
209+
193210
.. function:: unregister(signum)
194211

195212
Unregister a user signal: uninstall the handler of the *signum* signal

0 commit comments

Comments
 (0)