Skip to content

Commit b1241ab

Browse files
committed
Merge remote-tracking branch 'upstream/main' into remove-mmap-resize
2 parents 2413ceb + 1ff2cbb commit b1241ab

File tree

178 files changed

+2569
-1263
lines changed

Some content is hidden

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

178 files changed

+2569
-1263
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ repos:
1414
name: Run Ruff (lint) on Tools/build/
1515
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
1616
files: ^Tools/build/
17+
- id: ruff
18+
name: Run Ruff (lint) on Tools/i18n/
19+
args: [--exit-non-zero-on-fix, --config=Tools/i18n/.ruff.toml]
20+
files: ^Tools/i18n/
1721
- id: ruff
1822
name: Run Ruff (lint) on Argument Clinic
1923
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]

Doc/extending/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ A pointer to the module definition must be returned via :c:func:`PyModuleDef_Ini
426426
so that the import machinery can create the module and store it in ``sys.modules``.
427427

428428
When embedding Python, the :c:func:`!PyInit_spam` function is not called
429-
automatically unless there's an entry in the :c:data:`PyImport_Inittab` table.
429+
automatically unless there's an entry in the :c:data:`!PyImport_Inittab` table.
430430
To add the module to the initialization table, use :c:func:`PyImport_AppendInittab`,
431431
optionally followed by an import of the module::
432432

Doc/glossary.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Glossary
2121
right delimiters (parentheses, square brackets, curly braces or triple
2222
quotes), or after specifying a decorator.
2323

24-
* The :const:`Ellipsis` built-in constant.
24+
.. index:: single: ...; ellipsis literal
25+
26+
* The three dots form of the :ref:`Ellipsis <bltin-ellipsis-object>` object.
2527

2628
abstract base class
2729
Abstract base classes complement :term:`duck-typing` by

Doc/howto/descriptor.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Here are three practical data validation utilities:
420420

421421
def validate(self, value):
422422
if not isinstance(value, str):
423-
raise TypeError(f'Expected {value!r} to be an str')
423+
raise TypeError(f'Expected {value!r} to be a str')
424424
if self.minsize is not None and len(value) < self.minsize:
425425
raise ValueError(
426426
f'Expected {value!r} to be no smaller than {self.minsize!r}'

Doc/howto/instrumentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ should instead read:
269269
(assuming a :ref:`debug build <debug-build>` of CPython 3.6)
270270

271271

272+
.. _static-markers:
273+
272274
Available static markers
273275
------------------------
274276

Doc/library/constants.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ A small number of constants live in the built-in namespace. They are:
6565
.. index:: single: ...; ellipsis literal
6666
.. data:: Ellipsis
6767

68-
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
69-
with extended slicing syntax for user-defined container data types.
68+
The same as the ellipsis literal "``...``", an object frequently used to
69+
indicate that something is omitted. Assignment to ``Ellipsis`` is possible, but
70+
assignment to ``...`` raises a :exc:`SyntaxError`.
7071
``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type.
7172

7273

Doc/library/curses.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,10 @@ The module :mod:`curses` defines the following functions:
716716
Window Objects
717717
--------------
718718

719-
Window objects, as returned by :func:`initscr` and :func:`newwin` above, have
720-
the following methods and attributes:
719+
.. class:: window
720+
721+
Window objects, as returned by :func:`initscr` and :func:`newwin` above, have
722+
the following methods and attributes:
721723

722724

723725
.. method:: window.addch(ch[, attr])

Doc/library/hmac.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ cannot be used with HMAC.
5050
.. versionadded:: 3.7
5151

5252

53-
An HMAC object has the following methods:
53+
.. class:: HMAC
54+
55+
An HMAC object has the following methods:
5456

5557
.. method:: HMAC.update(msg)
5658

Doc/library/mmap.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ update the underlying file.
4848

4949
To map anonymous memory, -1 should be passed as the fileno along with the length.
5050

51-
.. class:: mmap(fileno, length, tagname=None, access=ACCESS_DEFAULT, offset=0)
51+
.. class:: mmap(fileno, length, tagname=None, \
52+
access=ACCESS_DEFAULT, offset=0, *, trackfd=True)
5253
5354
**(Windows version)** Maps *length* bytes from the file specified by the
54-
file handle *fileno*, and creates a mmap object. If *length* is larger
55+
file descriptor *fileno*, and creates a mmap object. If *length* is larger
5556
than the current size of the file, the file is extended to contain *length*
5657
bytes. If *length* is ``0``, the maximum length of the map is the current
5758
size of the file, except that if the file is empty Windows raises an
@@ -69,6 +70,17 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
6970
will be relative to the offset from the beginning of the file. *offset*
7071
defaults to 0. *offset* must be a multiple of the :const:`ALLOCATIONGRANULARITY`.
7172

73+
If *trackfd* is ``False``, the file handle corresponding to *fileno* will
74+
not be duplicated, and the resulting :class:`!mmap` object will not
75+
be associated with the map's underlying file.
76+
This means that the :meth:`~mmap.mmap.size` and :meth:`~mmap.mmap.resize`
77+
methods will fail.
78+
This mode is useful to limit the number of open file handles.
79+
The original file can be renamed (but not deleted) after closing *fileno*.
80+
81+
.. versionchanged:: next
82+
The *trackfd* parameter was added.
83+
7284
.. audit-event:: mmap.__new__ fileno,length,access,offset mmap.mmap
7385

7486
.. class:: mmap(fileno, length, flags=MAP_SHARED, prot=PROT_WRITE|PROT_READ, \
@@ -314,6 +326,10 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
314326

315327
Return the length of the file, which can be larger than the size of the
316328
memory-mapped area.
329+
For anonymous mapping, return its size.
330+
331+
.. versionchanged:: next
332+
Supports anonymous mapping on Unix.
317333

318334

319335
.. method:: tell()

Doc/library/profile.rst

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The Python standard library provides three different profiling implementations:
2828

2929
**Statistical Profiler:**
3030

31-
1. :mod:`profile.sample` provides statistical profiling of running Python processes
31+
1. :mod:`!profiling.sampling` provides statistical profiling of running Python processes
3232
using periodic stack sampling. It can attach to any running Python process without
3333
requiring code modification or restart, making it ideal for production debugging.
3434

@@ -55,26 +55,26 @@ The Python standard library provides three different profiling implementations:
5555

5656
**Profiler Comparison:**
5757

58-
+-------------------+----------------------+----------------------+----------------------+
59-
| Feature | Statistical | Deterministic | Deterministic |
60-
| | (``profile.sample``) | (``cProfile``) | (``profile``) |
61-
+===================+======================+======================+======================+
62-
| **Target** | Running process | Code you run | Code you run |
63-
+-------------------+----------------------+----------------------+----------------------+
64-
| **Overhead** | Virtually none | Moderate | High |
65-
+-------------------+----------------------+----------------------+----------------------+
66-
| **Accuracy** | Statistical approx. | Exact call counts | Exact call counts |
67-
+-------------------+----------------------+----------------------+----------------------+
68-
| **Setup** | Attach to any PID | Instrument code | Instrument code |
69-
+-------------------+----------------------+----------------------+----------------------+
70-
| **Use Case** | Production debugging | Development/testing | Profiler extension |
71-
+-------------------+----------------------+----------------------+----------------------+
72-
| **Implementation**| C extension | C extension | Pure Python |
73-
+-------------------+----------------------+----------------------+----------------------+
58+
+-------------------+--------------------------+----------------------+----------------------+
59+
| Feature | Statistical | Deterministic | Deterministic |
60+
| | (``profiling.sampling``) | (``cProfile``) | (``profile``) |
61+
+===================+==========================+======================+======================+
62+
| **Target** | Running process | Code you run | Code you run |
63+
+-------------------+--------------------------+----------------------+----------------------+
64+
| **Overhead** | Virtually none | Moderate | High |
65+
+-------------------+--------------------------+----------------------+----------------------+
66+
| **Accuracy** | Statistical approx. | Exact call counts | Exact call counts |
67+
+-------------------+--------------------------+----------------------+----------------------+
68+
| **Setup** | Attach to any PID | Instrument code | Instrument code |
69+
+-------------------+--------------------------+----------------------+----------------------+
70+
| **Use Case** | Production debugging | Development/testing | Profiler extension |
71+
+-------------------+--------------------------+----------------------+----------------------+
72+
| **Implementation**| C extension | C extension | Pure Python |
73+
+-------------------+--------------------------+----------------------+----------------------+
7474

7575
.. note::
7676

77-
The statistical profiler (:mod:`profile.sample`) is recommended for most production
77+
The statistical profiler (:mod:`!profiling.sampling`) is recommended for most production
7878
use cases due to its extremely low overhead and ability to profile running processes
7979
without modification. It can attach to any Python process and collect performance
8080
data with minimal impact on execution speed, making it ideal for debugging
@@ -138,11 +138,11 @@ on an existing application.
138138

139139
To profile an existing running process::
140140

141-
python -m profile.sample 1234
141+
python -m profiling.sampling 1234
142142

143143
To profile with custom settings::
144144

145-
python -m profile.sample -i 50 -d 30 1234
145+
python -m profiling.sampling -i 50 -d 30 1234
146146

147147
**Deterministic Profiling (Development/Testing):**
148148

@@ -218,34 +218,34 @@ them in various ways.
218218
Statistical Profiler Command Line Interface
219219
===========================================
220220

221-
.. program:: profile.sample
221+
.. program:: profiling.sampling
222222

223-
The :mod:`profile.sample` module can be invoked as a script to profile running processes::
223+
The :mod:`!profiling.sampling` module can be invoked as a script to profile running processes::
224224

225-
python -m profile.sample [options] PID
225+
python -m profiling.sampling [options] PID
226226

227227
**Basic Usage Examples:**
228228

229229
Profile process 1234 for 10 seconds with default settings::
230230

231-
python -m profile.sample 1234
231+
python -m profiling.sampling 1234
232232

233233
Profile with custom interval and duration, save to file::
234234

235-
python -m profile.sample -i 50 -d 30 -o profile.stats 1234
235+
python -m profiling.sampling -i 50 -d 30 -o profile.stats 1234
236236

237237
Generate collapsed stacks to use with tools like `flamegraph.pl
238238
<https://github.com/brendangregg/FlameGraph>`_::
239239

240-
python -m profile.sample --collapsed 1234
240+
python -m profiling.sampling --collapsed 1234
241241

242242
Profile all threads, sort by total time::
243243

244-
python -m profile.sample -a --sort-tottime 1234
244+
python -m profiling.sampling -a --sort-tottime 1234
245245

246246
Profile with real-time sampling statistics::
247247

248-
python -m profile.sample --realtime-stats 1234
248+
python -m profiling.sampling --realtime-stats 1234
249249

250250
**Command Line Options:**
251251

@@ -339,13 +339,13 @@ The statistical profiler produces output similar to deterministic profilers but
339339

340340
.. _profile-cli:
341341

342-
:mod:`profile.sample` Module Reference
342+
:mod:`!profiling.sampling` Module Reference
343343
=======================================================
344344

345-
.. module:: profile.sample
345+
.. module:: profiling.sampling
346346
:synopsis: Python statistical profiler.
347347

348-
This section documents the programmatic interface for the :mod:`profile.sample` module.
348+
This section documents the programmatic interface for the :mod:`!profiling.sampling` module.
349349
For command-line usage, see :ref:`sampling-profiler-cli`. For conceptual information
350350
about statistical profiling, see :ref:`statistical-profiling`
351351

@@ -373,14 +373,14 @@ about statistical profiling, see :ref:`statistical-profiling`
373373
Examples::
374374

375375
# Basic usage - profile process 1234 for 10 seconds
376-
import profile.sample
377-
profile.sample.sample(1234)
376+
import profiling.sampling
377+
profiling.sampling.sample(1234)
378378

379379
# Profile with custom settings
380-
profile.sample.sample(1234, duration_sec=30, sample_interval_usec=50, all_threads=True)
380+
profiling.sampling.sample(1234, duration_sec=30, sample_interval_usec=50, all_threads=True)
381381

382382
# Generate collapsed stack traces for flamegraph.pl
383-
profile.sample.sample(1234, output_format='collapsed', filename='profile.collapsed')
383+
profiling.sampling.sample(1234, output_format='collapsed', filename='profile.collapsed')
384384

385385
.. class:: SampleProfiler(pid, sample_interval_usec, all_threads)
386386

@@ -856,7 +856,7 @@ What Is Deterministic Profiling?
856856
call*, *function return*, and *exception* events are monitored, and precise
857857
timings are made for the intervals between these events (during which time the
858858
user's code is executing). In contrast, :dfn:`statistical profiling` (which is
859-
provided by the :mod:`profile.sample` module) periodically samples the effective instruction pointer, and
859+
provided by the :mod:`!profiling.sampling` module) periodically samples the effective instruction pointer, and
860860
deduces where time is being spent. The latter technique traditionally involves
861861
less overhead (as the code does not need to be instrumented), but provides only
862862
relative indications of where time is being spent.

0 commit comments

Comments
 (0)