Skip to content

Commit d2af12f

Browse files
committed
Merge branch 'main' into unify-tier-2-for-iter
2 parents df2792f + a6b610a commit d2af12f

Some content is hidden

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

63 files changed

+1447
-440
lines changed

Android/android-env.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ done
6161
export CFLAGS=""
6262
export LDFLAGS="-Wl,--build-id=sha1 -Wl,--no-rosegment"
6363

64+
# Unlike Linux, Android does not implicitly use a dlopened library to resolve
65+
# relocations in subsequently-loaded libraries, even if RTLD_GLOBAL is used
66+
# (https://github.com/android/ndk/issues/1244). So any library that fails to
67+
# build with this flag, would also fail to load at runtime.
68+
LDFLAGS="$LDFLAGS -Wl,--no-undefined"
69+
6470
# Many packages get away with omitting -lm on Linux, but Android is stricter.
6571
LDFLAGS="$LDFLAGS -lm"
6672

Doc/c-api/time.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ with the :term:`GIL` held.
7272
See :func:`time.time` for details important on this clock.
7373
7474
75+
Raw Clock Functions
76+
-------------------
77+
78+
Similar to clock functions, but don't set an exception on error and don't
79+
require the caller to hold the GIL.
80+
81+
On success, the functions return ``0``.
82+
83+
On failure, they set ``*result`` to ``0`` and return ``-1``, *without* setting
84+
an exception. To get the cause of the error, acquire the GIL and call the
85+
regular (non-``Raw``) function. Note that the regular function may succeed after
86+
the ``Raw`` one failed.
87+
88+
.. c:function:: int PyTime_MonotonicRaw(PyTime_t *result)
89+
90+
Similar to :c:func:`PyTime_Monotonic`,
91+
but don't set an exception on error and don't require holding the GIL.
92+
93+
.. c:function:: int PyTime_PerfCounterRaw(PyTime_t *result)
94+
95+
Similar to :c:func:`PyTime_PerfCounter`,
96+
but don't set an exception on error and don't require holding the GIL.
97+
98+
.. c:function:: int PyTime_TimeRaw(PyTime_t *result)
99+
100+
Similar to :c:func:`PyTime_Time`,
101+
but don't set an exception on error and don't require holding the GIL.
102+
103+
75104
Conversion functions
76105
--------------------
77106

Doc/library/importlib.metadata.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,84 @@ metadata in locations other than the file system, subclass
406406
a custom finder, return instances of this derived ``Distribution`` in the
407407
``find_distributions()`` method.
408408

409+
Example
410+
-------
411+
412+
Consider for example a custom finder that loads Python
413+
modules from a database::
414+
415+
class DatabaseImporter(importlib.abc.MetaPathFinder):
416+
def __init__(self, db):
417+
self.db = db
418+
419+
def find_spec(self, fullname, target=None) -> ModuleSpec:
420+
return self.db.spec_from_name(fullname)
421+
422+
sys.meta_path.append(DatabaseImporter(connect_db(...)))
423+
424+
That importer now presumably provides importable modules from a
425+
database, but it provides no metadata or entry points. For this
426+
custom importer to provide metadata, it would also need to implement
427+
``DistributionFinder``::
428+
429+
from importlib.metadata import DistributionFinder
430+
431+
class DatabaseImporter(DistributionFinder):
432+
...
433+
434+
def find_distributions(self, context=DistributionFinder.Context()):
435+
query = dict(name=context.name) if context.name else {}
436+
for dist_record in self.db.query_distributions(query):
437+
yield DatabaseDistribution(dist_record)
438+
439+
In this way, ``query_distributions`` would return records for
440+
each distribution served by the database matching the query. For
441+
example, if ``requests-1.0`` is in the database, ``find_distributions``
442+
would yield a ``DatabaseDistribution`` for ``Context(name='requests')``
443+
or ``Context(name=None)``.
444+
445+
For the sake of simplicity, this example ignores ``context.path``\. The
446+
``path`` attribute defaults to ``sys.path`` and is the set of import paths to
447+
be considered in the search. A ``DatabaseImporter`` could potentially function
448+
without any concern for a search path. Assuming the importer does no
449+
partitioning, the "path" would be irrelevant. In order to illustrate the
450+
purpose of ``path``, the example would need to illustrate a more complex
451+
``DatabaseImporter`` whose behavior varied depending on
452+
``sys.path``/``PYTHONPATH``. In that case, the ``find_distributions`` should
453+
honor the ``context.path`` and only yield ``Distribution``\ s pertinent to that
454+
path.
455+
456+
``DatabaseDistribution``, then, would look something like::
457+
458+
class DatabaseDistribution(importlib.metadata.Distributon):
459+
def __init__(self, record):
460+
self.record = record
461+
462+
def read_text(self, filename):
463+
"""
464+
Read a file like "METADATA" for the current distribution.
465+
"""
466+
if filename == "METADATA":
467+
return f"""Name: {self.record.name}
468+
Version: {self.record.version}
469+
"""
470+
if filename == "entry_points.txt":
471+
return "\n".join(
472+
f"""[{ep.group}]\n{ep.name}={ep.value}"""
473+
for ep in self.record.entry_points)
474+
475+
def locate_file(self, path):
476+
raise RuntimeError("This distribution has no file system")
477+
478+
This basic implementation should provide metadata and entry points for
479+
packages served by the ``DatabaseImporter``, assuming that the
480+
``record`` supplies suitable ``.name``, ``.version``, and
481+
``.entry_points`` attributes.
482+
483+
The ``DatabaseDistribution`` may also provide other metadata files, like
484+
``RECORD`` (required for ``Distribution.files``) or override the
485+
implementation of ``Distribution.files``. See the source for more inspiration.
486+
409487

410488
.. _`entry point API`: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points
411489
.. _`metadata API`: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#metadata-api

Doc/library/os.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ as internal buffering of data.
926926
If *offset_src* is None, then *src* is read from the current position;
927927
respectively for *offset_dst*.
928928

929-
In Linux kernel older than 5.3, the files pointed by *src* and *dst*
929+
In Linux kernel older than 5.3, the files pointed to by *src* and *dst*
930930
must reside in the same filesystem, otherwise an :exc:`OSError` is
931931
raised with :attr:`~OSError.errno` set to :const:`errno.EXDEV`.
932932

@@ -1720,7 +1720,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
17201720
At least one of the file descriptors must refer to a pipe. If *offset_src*
17211721
is None, then *src* is read from the current position; respectively for
17221722
*offset_dst*. The offset associated to the file descriptor that refers to a
1723-
pipe must be ``None``. The files pointed by *src* and *dst* must reside in
1723+
pipe must be ``None``. The files pointed to by *src* and *dst* must reside in
17241724
the same filesystem, otherwise an :exc:`OSError` is raised with
17251725
:attr:`~OSError.errno` set to :const:`errno.EXDEV`.
17261726

Doc/library/shutil.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Directory and files operations
242242
be copied as far as the platform allows; if false or omitted, the contents
243243
and metadata of the linked files are copied to the new tree.
244244

245-
When *symlinks* is false, if the file pointed by the symlink doesn't
245+
When *symlinks* is false, if the file pointed to by the symlink doesn't
246246
exist, an exception will be added in the list of errors raised in
247247
an :exc:`Error` exception at the end of the copy process.
248248
You can set the optional *ignore_dangling_symlinks* flag to true if you
@@ -447,10 +447,11 @@ Directory and files operations
447447
called. If no *cmd* would be called, return ``None``.
448448

449449
*mode* is a permission mask passed to :func:`os.access`, by default
450-
determining if the file exists and executable.
450+
determining if the file exists and is executable.
451451

452-
When no *path* is specified, the results of :func:`os.environ` are used,
453-
returning either the "PATH" value or a fallback of :data:`os.defpath`.
452+
*path* is a "``PATH`` string" specifying the lookup directory list. When no
453+
*path* is specified, the results of :func:`os.environ` are used, returning
454+
either the "PATH" value or a fallback of :data:`os.defpath`.
454455

455456
On Windows, the current directory is prepended to the *path* if *mode* does
456457
not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the

Doc/using/cmdline.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,11 @@ behavior can be controlled by setting different environment variables.
632632

633633
Setting the environment variable ``TERM`` to ``dumb`` will disable color.
634634

635-
If the environment variable ``FORCE_COLOR`` is set, then color will be
635+
If the |FORCE_COLOR|_ environment variable is set, then color will be
636636
enabled regardless of the value of TERM. This is useful on CI systems which
637637
aren’t terminals but can still display ANSI escape sequences.
638638

639-
If the environment variable ``NO_COLOR`` is set, Python will disable all color
639+
If the |NO_COLOR|_ environment variable is set, Python will disable all color
640640
in the output. This takes precedence over ``FORCE_COLOR``.
641641

642642
All these environment variables are used also by other tools to control color
@@ -645,6 +645,14 @@ output. To control the color output only in the Python interpreter, the
645645
precedence over ``NO_COLOR``, which in turn takes precedence over
646646
``FORCE_COLOR``.
647647

648+
.. Apparently this how you hack together a formatted link:
649+
650+
.. |FORCE_COLOR| replace:: ``FORCE_COLOR``
651+
.. _FORCE_COLOR: https://force-color.org/
652+
653+
.. |NO_COLOR| replace:: ``NO_COLOR``
654+
.. _NO_COLOR: https://no-color.org/
655+
648656
Options you shouldn't use
649657
~~~~~~~~~~~~~~~~~~~~~~~~~
650658

Doc/whatsnew/3.13.rst

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,18 @@ Improved Error Messages
100100

101101
* The interpreter now colorizes error messages when displaying tracebacks by default.
102102
This feature can be controlled via the new :envvar:`PYTHON_COLORS` environment
103-
variable as well as the canonical ``NO_COLOR`` and ``FORCE_COLOR`` environment
103+
variable as well as the canonical |NO_COLOR|_ and |FORCE_COLOR|_ environment
104104
variables. See also :ref:`using-on-controlling-color`.
105105
(Contributed by Pablo Galindo Salgado in :gh:`112730`.)
106106

107+
.. Apparently this how you hack together a formatted link:
108+
109+
.. |FORCE_COLOR| replace:: ``FORCE_COLOR``
110+
.. _FORCE_COLOR: https://force-color.org/
111+
112+
.. |NO_COLOR| replace:: ``NO_COLOR``
113+
.. _NO_COLOR: https://no-color.org/
114+
107115
* A common mistake is to write a script with the same name as a
108116
standard library module. When this results in errors, we now
109117
display a more helpful error message:
@@ -439,6 +447,12 @@ doctest
439447
:attr:`doctest.TestResults.skipped` attributes.
440448
(Contributed by Victor Stinner in :gh:`108794`.)
441449

450+
* Color is added to the output by default.
451+
This can be controlled via the new :envvar:`PYTHON_COLORS` environment
452+
variable as well as the canonical |NO_COLOR|_ and |FORCE_COLOR|_ environment
453+
variables. See also :ref:`using-on-controlling-color`.
454+
(Contributed by Hugo van Kemenade in :gh:`117225`.)
455+
442456
email
443457
-----
444458

@@ -932,7 +946,8 @@ The ``--enable-experimental-jit`` flag has the following optional values:
932946
The interpreter can be disabled by running with
933947
``PYTHON_JIT=0``.
934948

935-
(On Windows, use ``PCbuild/build.bat --enable-jit`` to enable the JIT.)
949+
(On Windows, use ``PCbuild/build.bat --experimental-jit`` to enable the JIT
950+
or ``--experimental-jit-interpreter`` to enable the Tier 2 interpreter.)
936951

937952
See :pep:`744` for more details.
938953

@@ -1901,9 +1916,15 @@ New Features
19011916

19021917
* :c:type:`PyTime_t` type.
19031918
* :c:var:`PyTime_MIN` and :c:var:`PyTime_MAX` constants.
1904-
* :c:func:`PyTime_AsSecondsDouble`
1905-
:c:func:`PyTime_Monotonic`, :c:func:`PyTime_PerfCounter`, and
1906-
:c:func:`PyTime_Time` functions.
1919+
* Add functions:
1920+
1921+
* :c:func:`PyTime_AsSecondsDouble`.
1922+
* :c:func:`PyTime_Monotonic`.
1923+
* :c:func:`PyTime_MonotonicRaw`.
1924+
* :c:func:`PyTime_PerfCounter`.
1925+
* :c:func:`PyTime_PerfCounterRaw`.
1926+
* :c:func:`PyTime_Time`.
1927+
* :c:func:`PyTime_TimeRaw`.
19071928

19081929
(Contributed by Victor Stinner and Petr Viktorin in :gh:`110850`.)
19091930

Include/cpython/code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ struct PyCodeObject _PyCode_DEF(1);
226226
*/
227227
#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
228228

229-
#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
229+
#define CO_MAXBLOCKS 21 /* Max static block nesting within a function */
230230

231231
PyAPI_DATA(PyTypeObject) PyCode_Type;
232232

Include/cpython/optimizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef struct _PyExecutorObject {
102102
uint32_t code_size;
103103
size_t jit_size;
104104
void *jit_code;
105+
void *jit_side_entry;
105106
_PyExitData exits[1];
106107
} _PyExecutorObject;
107108

Include/cpython/pytime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PyAPI_FUNC(int) PyTime_Monotonic(PyTime_t *result);
1616
PyAPI_FUNC(int) PyTime_PerfCounter(PyTime_t *result);
1717
PyAPI_FUNC(int) PyTime_Time(PyTime_t *result);
1818

19+
PyAPI_FUNC(int) PyTime_MonotonicRaw(PyTime_t *result);
20+
PyAPI_FUNC(int) PyTime_PerfCounterRaw(PyTime_t *result);
21+
PyAPI_FUNC(int) PyTime_TimeRaw(PyTime_t *result);
22+
1923
#ifdef __cplusplus
2024
}
2125
#endif

0 commit comments

Comments
 (0)