Skip to content

Commit fa17d1d

Browse files
authored
Merge branch 'main' into to_bool_specialization
2 parents a30ca62 + 24c4aec commit fa17d1d

162 files changed

Lines changed: 6763 additions & 1494 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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Tools/unicode/data/
140140
/.ccache
141141
/cross-build*/
142142
/jit_stencils*.h
143+
/jit_unwind_info*.h
143144
/platform
144145
/profile-clean-stamp
145146
/profile-run-stamp

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.18.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ Pending removal in Python 3.18
1010
specifier ``'N'``, which is only supported in the :mod:`!decimal` module's
1111
C implementation, has been deprecated since Python 3.13.
1212
(Contributed by Serhiy Storchaka in :gh:`89902`.)
13+
14+
* Deprecations defined by :pep:`829`:
15+
16+
* ``import`` lines in :file:`{name}.pth` files are silently ignored.
17+
18+
(Contributed by Barry Warsaw in :gh:`148641`.)

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

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

4040
(Contributed by Hugo van Kemenade and Stan Ulbrych in :gh:`76007`.)
41+
42+
* Deprecations defined by :pep:`829`:
43+
44+
* Warnings are produced for ``import`` lines found in :file:`{name}.pth`
45+
files.
46+
47+
* :file:`{name}.pth` files are no longer decoded in the locale encoding by
48+
default. They **MUST** be encoded in ``utf-8-sig``.
49+
50+
(Contributed by Barry Warsaw in :gh:`148641`.)
51+
52+
* :mod:`ast`:
53+
54+
* Creating instances of abstract AST nodes (such as :class:`ast.AST`
55+
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

0 commit comments

Comments
 (0)