Skip to content

Commit 30819fe

Browse files
Merge branch 'main' into add_test_xpickle
2 parents 552f358 + d6f77e6 commit 30819fe

Some content is hidden

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

47 files changed

+1913
-1296
lines changed

Doc/library/compression.zstd.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Reading and writing compressed files
7373
argument is not None, a :exc:`!TypeError` will be raised.
7474

7575
When writing, the *options* argument can be a dictionary
76-
providing advanced decompression parameters; see
76+
providing advanced compression parameters; see
7777
:class:`CompressionParameter` for detailed information about supported
7878
parameters. The *level* argument is the compression level to use when
7979
writing compressed data. Only one of *level* or *options* may be non-None.
@@ -117,7 +117,7 @@ Reading and writing compressed files
117117
argument is not None, a :exc:`!TypeError` will be raised.
118118

119119
When writing, the *options* argument can be a dictionary
120-
providing advanced decompression parameters; see
120+
providing advanced compression parameters; see
121121
:class:`CompressionParameter` for detailed information about supported
122122
parameters. The *level* argument is the compression level to use when
123123
writing compressed data. Only one of *level* or *options* may be passed. The

Doc/library/importlib.metadata.rst

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ Distributions
418418
equal, even if they relate to the same installed distribution and
419419
accordingly have the same attributes.
420420

421+
.. method:: discover(cls, *, context=None, **kwargs)
422+
423+
Returns an iterable of :class:`Distribution` instances for all packages.
424+
425+
The optional argument *context* is a :class:`DistributionFinder.Context`
426+
instance, used to modify the search for distributions. Alternatively,
427+
*kwargs* may contain keyword arguments for constructing a new
428+
:class:`!DistributionFinder.Context`.
429+
430+
421431
While the module level API described above is the most common and convenient usage,
422432
you can get all of that information from the :class:`!Distribution` class.
423433
:class:`!Distribution` is an abstract object that represents the metadata for
@@ -466,6 +476,61 @@ This metadata finder search defaults to ``sys.path``, but varies slightly in how
466476
- ``importlib.metadata`` does not honor :class:`bytes` objects on ``sys.path``.
467477
- ``importlib.metadata`` will incidentally honor :py:class:`pathlib.Path` objects on ``sys.path`` even though such values will be ignored for imports.
468478

479+
.. class:: DistributionFinder
480+
481+
A :class:`~importlib.abc.MetaPathFinder` subclass capable of discovering
482+
installed distributions.
483+
484+
Custom providers should implement this interface in order to
485+
supply metadata.
486+
487+
.. class:: Context(**kwargs)
488+
489+
A :class:`!Context` gives a custom provider a means to
490+
solicit additional details from the callers of distribution discovery
491+
functions like :func:`distributions` or :meth:`Distribution.discover`
492+
beyond :attr:`!.name` and :attr:`!.path` when searching
493+
for distributions.
494+
495+
For example, a provider could expose suites of packages in either a
496+
"public" or "private" ``realm``. A caller of distribution discovery
497+
functions may wish to query only for distributions in a particular realm
498+
and could call ``distributions(realm="private")`` to signal to the
499+
custom provider to only include distributions from that
500+
realm.
501+
502+
Each :class:`!DistributionFinder` must expect any parameters and should
503+
attempt to honor the canonical parameters defined below when
504+
appropriate.
505+
506+
See the section on :ref:`implementing-custom-providers` for more details.
507+
508+
.. attribute:: name
509+
510+
Specific name for which a distribution finder should match.
511+
512+
A :attr:`!.name` of ``None`` matches all distributions.
513+
514+
.. attribute:: path
515+
516+
A property providing the sequence of directory paths that a
517+
distribution finder should search.
518+
519+
Typically refers to Python installed package paths such as
520+
"site-packages" directories and defaults to :attr:`sys.path`.
521+
522+
523+
.. function:: distributions(**kwargs)
524+
525+
Returns an iterable of :class:`Distribution` instances for all packages.
526+
527+
The *kwargs* argument may contain either a keyword argument ``context``, a
528+
:class:`DistributionFinder.Context` instance, or pass keyword arguments for
529+
constructing a new :class:`!DistributionFinder.Context`. The
530+
:class:`!DistributionFinder.Context` is used to modify the search for
531+
distributions.
532+
533+
.. _implementing-custom-providers:
469534

470535
Implementing Custom Providers
471536
=============================
@@ -493,7 +558,7 @@ interface expected of finders by Python's import system.
493558
``importlib.metadata`` extends this protocol by looking for an optional
494559
``find_distributions`` callable on the finders from
495560
:data:`sys.meta_path` and presents this extended interface as the
496-
``DistributionFinder`` abstract base class, which defines this abstract
561+
:class:`DistributionFinder` abstract base class, which defines this abstract
497562
method::
498563

499564
@abc.abstractmethod
@@ -502,9 +567,11 @@ method::
502567
loading the metadata for packages for the indicated ``context``.
503568
"""
504569

505-
The ``DistributionFinder.Context`` object provides ``.path`` and ``.name``
506-
properties indicating the path to search and name to match and may
507-
supply other relevant context sought by the consumer.
570+
The :class:`DistributionFinder.Context` object provides
571+
:attr:`~DistributionFinder.Context.path` and
572+
:attr:`~DistributionFinder.Context.name` properties indicating the path to
573+
search and name to match and may supply other relevant context sought by the
574+
consumer.
508575

509576
In practice, to support finding distribution package
510577
metadata in locations other than the file system, subclass
@@ -529,7 +596,7 @@ Imagine a custom finder that loads Python modules from a database::
529596
That importer now presumably provides importable modules from a
530597
database, but it provides no metadata or entry points. For this
531598
custom importer to provide metadata, it would also need to implement
532-
``DistributionFinder``::
599+
:class:`DistributionFinder`::
533600

534601
from importlib.metadata import DistributionFinder
535602

Doc/library/profiling.sampling.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -878,9 +878,9 @@ interesting functions that highlights:
878878

879879
Use :option:`--no-summary` to suppress both the legend and summary sections.
880880

881-
To save pstats output to a file instead of stdout::
881+
To save pstats output to a binary file instead of stdout::
882882

883-
python -m profiling.sampling run -o profile.txt script.py
883+
python -m profiling.sampling run -o profile.pstats script.py
884884

885885
The pstats format supports several options for controlling the display.
886886
The :option:`--sort` option determines the column used for ordering results::
@@ -1455,7 +1455,9 @@ Output options
14551455

14561456
.. option:: --pstats
14571457

1458-
Generate text statistics output. This is the default.
1458+
Generate pstats statistics. This is the default.
1459+
When written to stdout, the output is a text table; with :option:`-o`,
1460+
it is a binary pstats file.
14591461

14601462
.. option:: --collapsed
14611463

@@ -1486,8 +1488,9 @@ Output options
14861488
.. option:: -o <path>, --output <path>
14871489

14881490
Output file or directory path. Default behavior varies by format:
1489-
:option:`--pstats` writes to stdout, while other formats generate a file
1490-
named ``<format>_<PID>.<ext>`` (for example, ``flamegraph_12345.html``).
1491+
:option:`--pstats` prints a text table to stdout, while ``-o`` writes a
1492+
binary pstats file. Other formats generate a file named
1493+
``<format>_<PID>.<ext>`` (for example, ``flamegraph_12345.html``).
14911494
:option:`--heatmap` creates a directory named ``heatmap_<PID>``.
14921495

14931496
.. option:: --browser

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ that may require changes to your code.
14121412
:func:`resource.setrlimit` and :func:`resource.prlimit` is now deprecated.
14131413
(Contributed by Serhiy Storchaka in :gh:`137044`.)
14141414

1415-
* :meth:`~mmap.mmap.resize` has been removed on platforms that don't support the
1415+
* :meth:`mmap.mmap.resize` has been removed on platforms that don't support the
14161416
underlying syscall, instead of raising a :exc:`SystemError`.
14171417

14181418
* A resource warning is now emitted for an unclosed

Include/internal/pycore_backoff.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212
#include <assert.h>
1313
#include <stdbool.h>
1414
#include "pycore_structs.h" // _Py_BackoffCounter
15+
#include "pycore_tstate.h" // _PyPolicy
1516

1617
/* 16-bit countdown counters using exponential backoff.
1718
@@ -127,10 +128,11 @@ trigger_backoff_counter(void)
127128
#define JUMP_BACKWARD_INITIAL_VALUE 4000
128129
#define JUMP_BACKWARD_INITIAL_BACKOFF 6
129130
static inline _Py_BackoffCounter
130-
initial_jump_backoff_counter(void)
131+
initial_jump_backoff_counter(_PyPolicy *policy)
131132
{
132-
return make_backoff_counter(JUMP_BACKWARD_INITIAL_VALUE,
133-
JUMP_BACKWARD_INITIAL_BACKOFF);
133+
return make_backoff_counter(
134+
policy->interp.jump_backward_initial_value,
135+
policy->interp.jump_backward_initial_backoff);
134136
}
135137

136138
/* Initial exit temperature.
@@ -141,10 +143,11 @@ initial_jump_backoff_counter(void)
141143
#define SIDE_EXIT_INITIAL_BACKOFF 6
142144

143145
static inline _Py_BackoffCounter
144-
initial_temperature_backoff_counter(void)
146+
initial_temperature_backoff_counter(_PyPolicy *policy)
145147
{
146-
return make_backoff_counter(SIDE_EXIT_INITIAL_VALUE,
147-
SIDE_EXIT_INITIAL_BACKOFF);
148+
return make_backoff_counter(
149+
policy->jit.side_exit_initial_value,
150+
policy->jit.side_exit_initial_backoff);
148151
}
149152

150153
/* Unreachable backoff counter. */

Include/internal/pycore_magic_number.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ Known values:
286286
Python 3.15a1 3653 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
287287
Python 3.15a1 3654 (Fix missing exception handlers in logical expression)
288288
Python 3.15a1 3655 (Fix miscompilation of some module-level annotations)
289-
Python 3.15a1 3656 (Add TRACE_RECORD instruction, for platforms with switch based interpreter)
289+
Python 3.15a2 3656 (Add TRACE_RECORD instruction, for platforms with switch based interpreter)
290+
Python 3.15a4 3657 (Add BINARY_OP_SUBSCR_USTR_INT)
290291
291292
292293
Python 3.16 will start with 3700
@@ -300,7 +301,7 @@ PC/launcher.c must also be updated.
300301
301302
*/
302303

303-
#define PYC_MAGIC_NUMBER 3656
304+
#define PYC_MAGIC_NUMBER 3657
304305
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
305306
(little-endian) and then appending b'\r\n'. */
306307
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_tstate.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,24 @@ typedef struct _PyJitTracerState {
5252
_PyJitTracerInitialState initial_state;
5353
_PyJitTracerPreviousState prev_state;
5454
} _PyJitTracerState;
55+
5556
#endif
5657

58+
typedef struct _PyJitPolicy {
59+
uint16_t side_exit_initial_value;
60+
uint16_t side_exit_initial_backoff;
61+
} _PyJitPolicy;
62+
63+
typedef struct _PyInterpreterPolicy {
64+
uint16_t jump_backward_initial_value;
65+
uint16_t jump_backward_initial_backoff;
66+
} _PyInterpreterPolicy;
67+
68+
typedef struct _PyPolicy {
69+
_PyJitPolicy jit;
70+
_PyInterpreterPolicy interp;
71+
} _PyPolicy;
72+
5773
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
5874
// PyThreadState fields are exposed as part of the C API, although most fields
5975
// are intended to be private. The _PyThreadStateImpl fields not exposed.
@@ -132,6 +148,7 @@ typedef struct _PyThreadStateImpl {
132148
#if _Py_TIER2
133149
_PyJitTracerState jit_tracer_state;
134150
#endif
151+
_PyPolicy policy;
135152
} _PyThreadStateImpl;
136153

137154
#ifdef __cplusplus

0 commit comments

Comments
 (0)