Skip to content

Commit c79e48e

Browse files
authored
Merge branch 'main' into fix-json-str-subclass-separators
2 parents 8e1e24c + 2005753 commit c79e48e

52 files changed

Lines changed: 2072 additions & 330 deletions

Some content is hidden

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

‎Doc/library/fnmatch.rst‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
4646
a period are not special for this module, and are matched by the ``*`` and ``?``
4747
patterns.
4848

49-
Unless stated otherwise, "filename string" and "pattern string" either refer to
50-
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects. Note that the
49+
Unless stated otherwise, "filename string" and "pattern string" refer to
50+
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects.
51+
In addition to filename strings, :func:`.filter` and :func:`.filterfalse`
52+
accept :term:`path-like objects <path-like object>` in *names*. Note that the
5153
functions documented below do not allow to mix a :class:`!bytes` pattern with
5254
a :class:`!str` filename, and vice-versa.
5355

@@ -90,6 +92,9 @@ functions: :func:`~fnmatch.fnmatch`, :func:`fnmatchcase`, :func:`.filter`,
9092
It is the same as ``[n for n in names if fnmatch(n, pat)]``,
9193
but implemented more efficiently.
9294

95+
.. versionchanged:: next
96+
Added support for path-like objects in *names*.
97+
9398

9499
.. function:: filterfalse(names, pat)
95100

@@ -100,6 +105,9 @@ functions: :func:`~fnmatch.fnmatch`, :func:`fnmatchcase`, :func:`.filter`,
100105

101106
.. versionadded:: 3.14
102107

108+
.. versionchanged:: next
109+
Added support for path-like objects in *names*.
110+
103111

104112
.. function:: translate(pat)
105113

‎Doc/library/http.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The :mod:`!http` module also defines the following enums that help you work with
3535

3636
>>> from http import HTTPStatus
3737
>>> HTTPStatus.OK
38-
HTTPStatus.OK
38+
<HTTPStatus.OK: 200>
3939
>>> HTTPStatus.OK == 200
4040
True
4141
>>> HTTPStatus.OK.value
@@ -45,7 +45,7 @@ The :mod:`!http` module also defines the following enums that help you work with
4545
>>> HTTPStatus.OK.description
4646
'Request fulfilled, document follows'
4747
>>> list(HTTPStatus)
48-
[HTTPStatus.CONTINUE, HTTPStatus.SWITCHING_PROTOCOLS, ...]
48+
[<HTTPStatus.CONTINUE: 100>, <HTTPStatus.SWITCHING_PROTOCOLS: 101>, ...]
4949

5050
.. _http-status-codes:
5151

‎Doc/library/profiling.sampling.rst‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,14 @@ data, similar to the ``top`` command for system processes::
13211321

13221322
.. only:: not latex
13231323

1324-
.. figure:: tachyon-live-mode-2.gif
1324+
.. figure:: tachyon-live-mode-2.svg
13251325
:alt: Tachyon live mode showing all threads
13261326
:align: center
13271327
:width: 100%
13281328

1329+
.. This screenshot has been rendered with this one-liner CLI:
1330+
uvx 'click-extra==10.3.1' screenshot --record --columns 120 --rows 47 --start 6 --end 10 --hold 0 --blank 0 --preset plain --prompt '' --watermark '' --margin 0 --padding 0 --shadow none --border none --output tachyon-live-mode-2.svg -- python3.15 -m profiling.sampling run --live --all-threads --sampling-rate 10khz -m test test_gc test_threading test_list test_dict
1331+
13291332
Live mode displays real-time profiling statistics, showing combined
13301333
data from multiple threads in a multi-threaded application.
13311334

@@ -1346,11 +1349,14 @@ frequently, including specialized variants and their base opcodes.
13461349

13471350
.. only:: not latex
13481351

1349-
.. figure:: tachyon-live-mode-1.gif
1352+
.. figure:: tachyon-live-mode-1.svg
13501353
:alt: Tachyon live mode with opcode panel
13511354
:align: center
13521355
:width: 100%
13531356

1357+
.. This screenshot has been rendered with this one-liner CLI:
1358+
uvx 'click-extra==10.3.1' screenshot --record --columns 120 --rows 47 --start 6 --end 10 --hold 0 --blank 0 --preset plain --prompt '' --watermark '' --margin 0 --padding 0 --shadow none --border none --output tachyon-live-mode-1.svg -- python3.15 -m profiling.sampling run --live --all-threads --sampling-rate 10khz --opcodes -m test test_gc test_threading test_list test_dict
1359+
13541360
Live mode with ``--opcodes`` enabled shows an opcode panel with a bytecode
13551361
instruction breakdown for the selected function.
13561362

-803 KB
Binary file not shown.

‎Doc/library/tachyon-live-mode-1.svg‎

Lines changed: 359 additions & 0 deletions
Loading
-943 KB
Binary file not shown.

‎Doc/library/tachyon-live-mode-2.svg‎

Lines changed: 422 additions & 0 deletions
Loading

‎InternalDocs/profiling_binary_format.md‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ network streams.
119119

120120
## Sample Data
121121

122-
Sample data begins at offset 64 and extends to `string_table_offset`. Samples
123-
are grouped into blocks of at most 1 MiB of decoded data. Within a block,
124-
samples use delta compression to minimize redundancy when consecutive samples
125-
from the same thread have identical or similar call stacks. Each block can be
126-
decoded on its own once the string and frame tables are loaded, so a reader
127-
only needs to decode one block at a time.
122+
Sample data begins at offset 64 and extends to `string_table_offset`. Each
123+
block has a header followed by its columns. The columns together take at most
124+
1 MiB on disk and at most 1 MiB when decoded. Within a block, samples use
125+
delta compression to minimize redundancy when consecutive samples from the
126+
same thread have identical or similar call stacks. Once the reader loads the
127+
string and frame tables, it can decode each block on its own.
128128

129129
### Block Format
130130

@@ -659,16 +659,25 @@ patterns benefit from kernel read-ahead.
659659

660660
The implementation uses `madvise()` to hint the access pattern to the kernel:
661661
`MADV_SEQUENTIAL` indicates the file will be read linearly, enabling
662-
aggressive read-ahead. `MADV_WILLNEED` requests pre-faulting of pages.
663-
On Linux, `MAP_POPULATE` pre-faults all pages at mmap time rather than on
664-
first access, moving page fault overhead from the parsing loop to the
665-
initial mapping for more predictable performance. For large files (over
666-
32 MB), `MADV_HUGEPAGE` requests transparent huge pages (2 MB instead of
667-
4 KB) to reduce TLB pressure when accessing large amounts of data.
668-
669-
On Windows, the implementation falls back to standard file I/O with full
670-
file buffering. Profiling data files are typically small enough (tens to
671-
hundreds of megabytes) that this is acceptable.
662+
aggressive read-ahead. For large files (over 32 MB), `MADV_HUGEPAGE` requests
663+
transparent huge pages (2 MB instead of 4 KB) to reduce TLB pressure when
664+
accessing large amounts of data. Pages are not loaded up front, only when
665+
replay reaches them.
666+
667+
On Linux, the reader also gives back memory it no longer needs. Once the
668+
string and frame tables have been parsed, and after each sample block has
669+
been replayed, it uses `MADV_DONTNEED` to tell the kernel those pages can be
670+
dropped. The mapping is read-only, so if a dropped page is needed again, the
671+
kernel reads it back from the file. This keeps the memory used for sample
672+
data small, however large the file is.
673+
674+
On Windows, the reader uses standard file I/O instead. When a file is opened,
675+
it only reads the header and the part after the sample data, which holds the
676+
string and frame tables, the statistics and the footer. During replay,
677+
samples are read into a reusable buffer. The reader requests the smaller of
678+
2 MiB and the sample section size. A complete block, including its header,
679+
fits in this buffer. When the buffer runs low, the bytes not yet
680+
replayed are moved to the start and the rest is filled from the file.
672681

673682
The writer buffers samples in the current block and writes each completed
674683
block with a single call, so individual samples never cause a write.

‎Lib/_ast_unparse.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,15 @@ def _write_ftstring_inner(self, node, is_format_spec=False):
638638
for value in node.values:
639639
self._write_ftstring_inner(value, is_format_spec=is_format_spec)
640640
elif isinstance(node, Constant) and isinstance(node.value, str):
641-
value = node.value.replace("{", "{{").replace("}", "}}")
642-
641+
value = node.value
643642
if is_format_spec:
644643
value = value.replace("\\", "\\\\")
644+
value = value.replace("{", "\\x7b").replace("}", "\\x7d")
645645
value = value.replace("'", "\\'")
646646
value = value.replace('"', '\\"')
647647
value = value.replace("\n", "\\n")
648+
else:
649+
value = value.replace("{", "{{").replace("}", "}}")
648650
self.write(value)
649651
elif isinstance(node, FormattedValue):
650652
self.visit_FormattedValue(node)

‎Lib/fnmatch.py‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"""
1212

1313
import functools
14-
import itertools
1514
import os
16-
import posixpath
1715
import re
1816

1917
__all__ = ["filter", "filterfalse", "fnmatch", "fnmatchcase", "translate"]
@@ -52,34 +50,22 @@ def _compile_pattern(pat):
5250

5351
def filter(names, pat):
5452
"""Construct a list from those elements of the iterable NAMES that match PAT."""
55-
result = []
5653
pat = os.path.normcase(pat)
5754
match = _compile_pattern(pat)
58-
if os.path is posixpath:
59-
# normcase on posix is NOP. Optimize it away from the loop.
60-
for name in names:
61-
if match(name):
62-
result.append(name)
63-
else:
64-
for name in names:
65-
if match(os.path.normcase(name)):
66-
result.append(name)
67-
return result
55+
return [
56+
name for name in names
57+
if match(os.path.normcase(name))
58+
]
6859

6960

7061
def filterfalse(names, pat):
7162
"""Construct a list from those elements of the iterable NAMES that do not match PAT."""
7263
pat = os.path.normcase(pat)
7364
match = _compile_pattern(pat)
74-
if os.path is posixpath:
75-
# normcase on posix is NOP. Optimize it away from the loop.
76-
return list(itertools.filterfalse(match, names))
77-
78-
result = []
79-
for name in names:
80-
if match(os.path.normcase(name)) is None:
81-
result.append(name)
82-
return result
65+
return [
66+
name for name in names
67+
if not match(os.path.normcase(name))
68+
]
8369

8470

8571
def fnmatchcase(name, pat):

0 commit comments

Comments
 (0)