Skip to content

Commit 52c4f5e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into gh-149306-wave-error-messages
2 parents d1ba708 + c1940bc commit 52c4f5e

141 files changed

Lines changed: 5356 additions & 1242 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/glossary.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ Glossary
3939
ABCs with the :mod:`abc` module.
4040

4141
annotate function
42-
A function that can be called to retrieve the :term:`annotations <annotation>`
43-
of an object. This function is accessible as the :attr:`~object.__annotate__`
44-
attribute of functions, classes, and modules. Annotate functions are a
45-
subset of :term:`evaluate functions <evaluate function>`.
42+
A callable that can be called to retrieve the :term:`annotations <annotation>` of
43+
an object. Annotate functions are usually :term:`functions <function>`,
44+
automatically generated as the :attr:`~object.__annotate__` attribute of functions,
45+
classes, and modules. Annotate functions are a subset of
46+
:term:`evaluate functions <evaluate function>`.
4647

4748
annotation
4849
A label associated with a variable, a class

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,81 @@ annotations from the class and puts them in a separate attribute:
510510
return typ
511511
512512
513+
Creating a custom callable annotate function
514+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
515+
516+
Custom :term:`annotate functions <annotate function>` may be literal functions like those
517+
automatically generated for functions, classes, and modules. Or, they may wish to utilise
518+
the encapsulation provided by classes, in which case any :term:`callable` can be used as
519+
an :term:`annotate function`.
520+
521+
To provide the :attr:`~Format.VALUE`, :attr:`~Format.STRING`, or
522+
:attr:`~Format.FORWARDREF` formats directly, an :term:`annotate function` must provide
523+
the following attribute:
524+
525+
* A callable ``__call__`` with signature ``__call__(format, /) -> dict``, that does not
526+
raise a :exc:`NotImplementedError` when called with a supported format.
527+
528+
To provide the :attr:`~Format.VALUE_WITH_FAKE_GLOBALS` format, which is used to
529+
automatically generate :attr:`~Format.STRING` or :attr:`~Format.FORWARDREF` if they are
530+
not supported directly, :term:`annotate functions <annotate function>` must provide the
531+
following attributes:
532+
533+
* A callable ``__call__`` with signature ``__call__(format, /) -> dict``, that does not
534+
raise a :exc:`NotImplementedError` when called with
535+
:attr:`~Format.VALUE_WITH_FAKE_GLOBALS`.
536+
* A :ref:`code object <code-objects>` ``__code__`` containing the compiled code for the
537+
annotate function.
538+
* Optional: A tuple of the function's positional defaults ``__kwdefaults__``, if the
539+
function represented by ``__code__`` uses any positional defaults.
540+
* Optional: A dict of the function's keyword defaults ``__defaults__``, if the function
541+
represented by ``__code__`` uses any keyword defaults.
542+
* Optional: All other :ref:`function attributes <inspect-types>`.
543+
544+
.. code-block:: python
545+
546+
class Annotate:
547+
called_formats = []
548+
549+
def __call__(self, format=None, /, *, _self=None):
550+
# When called with fake globals, `_self` will be the
551+
# actual self value, and `self` will be the format.
552+
if _self is not None:
553+
self, format = _self, self
554+
555+
self.called_formats.append(format)
556+
if format <= 2: # VALUE or VALUE_WITH_FAKE_GLOBALS
557+
return {"x": MyType}
558+
raise NotImplementedError
559+
560+
__code__ = __call__.__code__
561+
__defaults__ = (None,)
562+
__kwdefaults__ = property(lambda self: dict(_self=self))
563+
564+
__globals__ = {}
565+
__builtins__ = {}
566+
__closure__ = None
567+
568+
This can then be called with:
569+
570+
.. code-block:: pycon
571+
572+
>>> from annotationlib import call_annotate_function, Format
573+
>>> call_annotate_function(Annotate(), format=Format.STRING)
574+
{'x': 'MyType'}
575+
576+
Or used as the annotate function for an object:
577+
578+
.. code-block:: pycon
579+
580+
>>> from annotationlib import get_annotations, Format
581+
>>> class C:
582+
... pass
583+
>>> C.__annotate__ = Annotate()
584+
>>> get_annotations(Annotate(), format=Format.STRING)
585+
{'x': 'MyType'}
586+
587+
513588
Limitations of the ``STRING`` format
514589
------------------------------------
515590

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

0 commit comments

Comments
 (0)