Skip to content

Commit 94e37fa

Browse files
authored
Merge branch 'main' into main
2 parents 0c05bc8 + 3ff00c7 commit 94e37fa

26 files changed

+354
-97
lines changed

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.

Doc/library/winreg.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ This module offers the following functions:
173173
See :ref:`above <exception-changed>`.
174174

175175

176+
.. function:: DeleteTree(key, sub_key=None)
177+
178+
Deletes the specified key and all its subkeys and values recursively.
179+
180+
*key* is an already open key, or one of the predefined
181+
:ref:`HKEY_* constants <hkey-constants>`.
182+
183+
*sub_key* is a string that names the subkey to delete. If ``None``,
184+
deletes all subkeys and values of the specified key.
185+
186+
This function deletes a key and all its descendants. If *sub_key* is
187+
``None``, all subkeys and values of the specified key are deleted.
188+
189+
.. audit-event:: winreg.DeleteTree key,sub_key winreg.DeleteTree
190+
191+
.. versionadded:: next
192+
193+
176194
.. function:: DeleteValue(key, value)
177195

178196
Removes a named value from a registry key.

Doc/reference/compound_stmts.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,14 @@ clauses.
416416
--------------------------
417417

418418
If :keyword:`!finally` is present, it specifies a 'cleanup' handler. The
419-
:keyword:`try` clause is executed, including any :keyword:`except` and
420-
:keyword:`else` clauses. If an exception occurs in any of the clauses and is
421-
not handled, the exception is temporarily saved. The :keyword:`!finally` clause
422-
is executed. If there is a saved exception it is re-raised at the end of the
423-
:keyword:`!finally` clause. If the :keyword:`!finally` clause raises another
424-
exception, the saved exception is set as the context of the new exception.
419+
:keyword:`try` clause is executed, including any :keyword:`except`
420+
and :keyword:`else <except_else>` clauses.
421+
If an exception occurs in any of the clauses and is not handled,
422+
the exception is temporarily saved.
423+
The :keyword:`!finally` clause is executed. If there is a saved exception
424+
it is re-raised at the end of the :keyword:`!finally` clause.
425+
If the :keyword:`!finally` clause raises another exception, the saved exception
426+
is set as the context of the new exception.
425427
If the :keyword:`!finally` clause executes a :keyword:`return`, :keyword:`break`
426428
or :keyword:`continue` statement, the saved exception is discarded. For example,
427429
this function returns 42.

Doc/reference/lexical_analysis.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,10 @@ to indicate that an ending quote ends the literal.
628628
STRING: [`stringprefix`] (`stringcontent`)
629629
stringprefix: <("r" | "u" | "b" | "br" | "rb"), case-insensitive>
630630
stringcontent:
631-
| "'" ( !"'" `stringitem`)* "'"
632-
| '"' ( !'"' `stringitem`)* '"'
633631
| "'''" ( !"'''" `longstringitem`)* "'''"
634632
| '"""' ( !'"""' `longstringitem`)* '"""'
633+
| "'" ( !"'" `stringitem`)* "'"
634+
| '"' ( !'"' `stringitem`)* '"'
635635
stringitem: `stringchar` | `stringescapeseq`
636636
stringchar: <any `source_character`, except backslash and newline>
637637
longstringitem: `stringitem` | newline

Doc/whatsnew/3.15.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ New features
7575
High frequency statistical sampling profiler
7676
--------------------------------------------
7777

78-
A new statistical sampling profiler has been added to the :mod:`profile` module as
79-
:mod:`profile.sample`. This profiler enables low-overhead performance analysis of
78+
A new statistical sampling profiler has been added to the new :mod:`!profiling` module as
79+
:mod:`!profiling.sampling`. This profiler enables low-overhead performance analysis of
8080
running Python processes without requiring code modification or process restart.
8181

8282
Unlike deterministic profilers (:mod:`cProfile` and :mod:`profile`) that instrument
@@ -97,19 +97,19 @@ Key features include:
9797

9898
Profile process 1234 for 10 seconds with default settings::
9999

100-
python -m profile.sample 1234
100+
python -m profiling.sampling 1234
101101

102102
Profile with custom interval and duration, save to file::
103103

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

106106
Generate collapsed stacks for flamegraph::
107107

108-
python -m profile.sample --collapsed 1234
108+
python -m profiling.sampling --collapsed 1234
109109

110110
Profile all threads and sort by total time::
111111

112-
python -m profile.sample -a --sort-tottime 1234
112+
python -m profiling.sampling -a --sort-tottime 1234
113113

114114
The profiler generates statistical estimates of where time is spent::
115115

Lib/test/test_grammar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,8 @@ def check(test):
15541554
check('[None [i, j]]')
15551555
check('[True [i, j]]')
15561556
check('[... [i, j]]')
1557+
check('[t"{x}" [i, j]]')
1558+
check('[t"x={x}" [i, j]]')
15571559

15581560
msg=r'indices must be integers or slices, not tuple; perhaps you missed a comma\?'
15591561
check('[(1, 2) [i, j]]')
@@ -1564,8 +1566,6 @@ def check(test):
15641566
check('[f"x={x}" [i, j]]')
15651567
check('["abc" [i, j]]')
15661568
check('[b"abc" [i, j]]')
1567-
check('[t"{x}" [i, j]]')
1568-
check('[t"x={x}" [i, j]]')
15691569

15701570
msg=r'indices must be integers or slices, not tuple;'
15711571
check('[[1, 2] [3, 4]]')
@@ -1586,6 +1586,7 @@ def check(test):
15861586
check('[[1, 2] [f"{x}"]]')
15871587
check('[[1, 2] [f"x={x}"]]')
15881588
check('[[1, 2] ["abc"]]')
1589+
msg=r'indices must be integers or slices, not string.templatelib.Template;'
15891590
check('[[1, 2] [t"{x}"]]')
15901591
check('[[1, 2] [t"x={x}"]]')
15911592
msg=r'indices must be integers or slices, not'

Lib/test/test_io/test_general.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5029,12 +5029,12 @@ def write(self, b: bytes):
50295029
pass
50305030

50315031
def test_reader_subclass(self):
5032-
self.assertIsSubclass(MyReader, io.Reader[bytes])
5033-
self.assertNotIsSubclass(str, io.Reader[bytes])
5032+
self.assertIsSubclass(self.MyReader, io.Reader)
5033+
self.assertNotIsSubclass(str, io.Reader)
50345034

50355035
def test_writer_subclass(self):
5036-
self.assertIsSubclass(MyWriter, io.Writer[bytes])
5037-
self.assertNotIsSubclass(str, io.Writer[bytes])
5036+
self.assertIsSubclass(self.MyWriter, io.Writer)
5037+
self.assertNotIsSubclass(str, io.Writer)
50385038

50395039

50405040
def load_tests(loader, tests, pattern):
@@ -5048,6 +5048,7 @@ def load_tests(loader, tests, pattern):
50485048
CTextIOWrapperTest, PyTextIOWrapperTest,
50495049
CMiscIOTest, PyMiscIOTest,
50505050
CSignalsTest, PySignalsTest, TestIOCTypes,
5051+
ProtocolsTest,
50515052
)
50525053

50535054
# Put the namespaces of the IO module we are testing and some useful mock

Lib/test/test_long.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,5 +1693,21 @@ class MyInt(int):
16931693
# GH-117195 -- This shouldn't crash
16941694
object.__sizeof__(1)
16951695

1696+
def test_hash(self):
1697+
# gh-136599
1698+
self.assertEqual(hash(-1), -2)
1699+
self.assertEqual(hash(0), 0)
1700+
self.assertEqual(hash(10), 10)
1701+
1702+
self.assertEqual(hash(sys.hash_info.modulus - 2), sys.hash_info.modulus - 2)
1703+
self.assertEqual(hash(sys.hash_info.modulus - 1), sys.hash_info.modulus - 1)
1704+
self.assertEqual(hash(sys.hash_info.modulus), 0)
1705+
self.assertEqual(hash(sys.hash_info.modulus + 1), 1)
1706+
1707+
self.assertEqual(hash(-sys.hash_info.modulus - 2), -2)
1708+
self.assertEqual(hash(-sys.hash_info.modulus - 1), -2)
1709+
self.assertEqual(hash(-sys.hash_info.modulus), 0)
1710+
self.assertEqual(hash(-sys.hash_info.modulus + 1), -sys.hash_info.modulus + 1)
1711+
16961712
if __name__ == "__main__":
16971713
unittest.main()

0 commit comments

Comments
 (0)