8000 Merge branch 'main' into tstrings · python/cpython@4e32db6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e32db6

Browse files
committed
Merge branch 'main' into tstrings
2 parents c8a9482 + 09b624b commit 4e32db6

File tree

131 files changed

+3509
-1886
lines changed

Some content is hidden

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

131 files changed

+3509
-1886
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ Include/internal/pycore_time.h @pganssle @abalkin
167167
**/*imap* @python/email-team
168168
**/*poplib* @python/email-team
169169

170+
# Exclude .mailmap from being owned by @python/email-team
171+
/.mailmap
172+
170173
# Garbage collector
171174
/Modules/gcmodule.c @pablogsal
172175
/Doc/library/gc.rst @pablogsal

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# This file sets the canonical name for contributors to the repository.
22
# Documentation: https://git-scm.com/docs/gitmailmap
3+
Willow Chargin <wchargin@gmail.com>
34
Amethyst Reese <amethyst@n7.gg> <john@noswap.com>

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.9.1
3+
rev: v0.11.4
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/
@@ -11,9 +11,9 @@ repos:
1111
args: [--exit-non-zero-on-fix]
1212
files: ^Lib/test/
1313
- id: ruff
14-
name: Run Ruff (lint) on Tools/build/check_warnings.py
14+
name: Run Ruff (lint) on Tools/build/
1515
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
16-
files: ^Tools/build/check_warnings.py
16+
files: ^Tools/build/
1717
- id: ruff
1818
name: Run Ruff (lint) on Argument Clinic
1919
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]

Doc/data/stable_abi.dat

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

Doc/howto/perf_profiling.rst

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,28 @@ files in the current directory which are ELF images for all the JIT trampolines
254254
that were created by Python.
255255

256256
.. warning::
257-
Notice that when using ``--call-graph dwarf`` the ``perf`` tool will take
257+
When using ``--call-graph dwarf``, the ``perf`` tool will take
258258
snapshots of the stack of the process being profiled and save the
259-
information in the ``perf.data`` file. By default the size of the stack dump
260-
is 8192 bytes but the user can change the size by passing the size after
261-
comma like ``--call-graph dwarf,4096``. The size of the stack dump is
262-
important because if the size is too small ``perf`` will not be able to
263-
unwind the stack and the output will be incomplete. On the other hand, if
264-
the size is too big, then ``perf`` won't be able to sample the process as
265-
frequently as it would like as the overhead will be higher.
259+
information in the ``perf.data`` file. By default, the size of the stack dump
260+
is 8192 bytes, but you can change the size by passing it after
261+
a comma like ``--call-graph dwarf,16384``.
266262

263+
The size of the stack dump is important because if the size is too small
264+
``perf`` will not be able to unwind the stack and the output will be
265+
incomplete. On the other hand, if the size is too big, then ``perf`` won't
266+
be able to sample the process as frequently as it would like as the overhead
267+
will be higher.
268+
269+
The stack size is particularly important when profiling Python code compiled
270+
with low optimization levels (like ``-O0``), as these builds tend to have
271+
larger stack frames. If you are compiling Python with ``-O0`` and not seeing
272+
Python functions in your profiling output, try increasing the stack dump
273+
size to 65528 bytes (the maximum)::
274+
275+
$ perf record -F 9999 -g -k 1 --call-graph dwarf,65528 -o perf.data python -Xperf_jit my_script.py
276+
277+
Different compilation flags can significantly impact stack sizes:
278+
279+
- Builds with ``-O0`` typically have much larger stack frames than those with ``-O1`` or higher
280+
- Adding optimizations (``-O1``, ``-O2``, etc.) typically reduces stack size
281+
- Frame pointers (``-fno-omit-frame-pointer``) generally provide more reliable stack unwinding

Doc/library/dis.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,6 @@ iterations of the loop.
13541354
If ``STACK[-1]`` is not ``None``, increments the bytecode counter by *delta*.
13551355
``STACK[-1]`` is popped.
13561356

1357-
This opcode is a pseudo-instruction, replaced in final bytecode by
1358-
the directed versions (forward/backward).
1359-
13601357
.. versionadded:: 3.11
13611358

13621359
.. versionchanged:: 3.12
@@ -1368,9 +1365,6 @@ iterations of the loop.
13681365
If ``STACK[-1]`` is ``None``, increments the bytecode counter by *delta*.
13691366
``STACK[-1]`` is popped.
13701367

1371-
This opcode is a pseudo-instruction, replaced in final bytecode by
1372-
the directed versions (forward/backward).
1373-
13741368
.. versionadded:: 3.11
13751369

13761370
.. versionchanged:: 3.12
@@ -1673,7 +1667,7 @@ iterations of the loop.
16731667
* ``oparg == 2``: call :func:`repr` on *value*
16741668
* ``oparg == 3``: call :func:`ascii` on *value*
16751669

1676-
Used for implementing formatted literal strings (f-strings).
1670+
Used for implementing formatted string literals (f-strings).
16771671

16781672
.. versionadded:: 3.13
16791673

@@ -1686,7 +1680,7 @@ iterations of the loop.
16861680
result = value.__format__("")
16871681
STACK.append(result)
16881682

1689-
Used for implementing formatted literal strings (f-strings).
1683+
Used for implementing formatted string literals (f-strings).
16901684

16911685
.. versionadded:: 3.13
16921686

@@ -1699,7 +1693,7 @@ iterations of the loop.
16991693
result = value.__format__(spec)
17001694
STACK.append(result)
17011695

1702-
Used for implementing formatted literal strings (f-strings).
1696+
Used for implementing formatted string literals (f-strings).
17031697

17041698
.. versionadded:: 3.13
17051699

Doc/library/hashlib.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
--------------
2222

23-
This module implements a common interface to many different secure hash and
24-
message digest algorithms. Included are the FIPS secure hash algorithms SHA1,
25-
SHA224, SHA256, SHA384, SHA512, (defined in `the FIPS 180-4 standard`_),
26-
the SHA-3 series (defined in `the FIPS 202 standard`_) as well as RSA's MD5
27-
algorithm (defined in internet :rfc:`1321`). The terms "secure hash" and
28-
"message digest" are interchangeable. Older algorithms were called message
29-
digests. The modern term is secure hash.
23+
This module implements a common interface to many different hash algorithms.
24+
Included are the FIPS secure hash algorithms SHA224, SHA256, SHA384, SHA512,
25+
(defined in `the FIPS 180-4 standard`_), the SHA-3 series (defined in `the FIPS
26+
202 standard`_) as well as the legacy algorithms SHA1 (`formerly part of FIPS`_)
27+
and the MD5 algorithm (defined in internet :rfc:`1321`).
3028

3129
.. note::
3230

@@ -812,6 +810,7 @@ Domain Dedication 1.0 Universal:
812810
.. _the FIPS 180-4 standard: https://csrc.nist.gov/pubs/fips/180-4/upd1/final
813811
.. _the FIPS 202 standard: https://csrc.nist.gov/pubs/fips/202/final
814812
.. _HACL\* project: https://github.com/hacl-star/hacl-star
813+
.. _formerly part of FIPS: https://csrc.nist.gov/news/2023/decision-to-revise-fips-180-4
815814

816815

817816
.. _hashlib-seealso:

Doc/library/itertools.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,12 @@ The following recipes have a more mathematical flavor:
10091009

10101010
.. testcode::
10111011

1012+
def multinomial(*counts):
1013+
"Number of distinct arrangements of a multiset."
1014+
# Counter('abracadabra').values() → 5 2 2 1 1
1015+
# multinomial(5, 2, 2, 1, 1) → 83160
1016+
return prod(map(comb, accumulate(counts), counts))
1017+
10121018
def powerset(iterable):
10131019
"Subsequences of the iterable from shortest to longest."
10141020
# powerset([1,2,3]) → () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)
@@ -1127,12 +1133,6 @@ The following recipes have a more mathematical flavor:
11271133
n -= n // prime
11281134
return n
11291135

1130-
def multinomial(*counts):
1131-
"Number of distinct arrangements of a multiset."
1132-
# Counter('abracadabra').values() → 5 2 2 1 1
1133-
# multinomial(5, 2, 2, 1, 1) → 83160
1134-
return prod(map(comb, accumulate(counts), counts))
1135-
11361136

11371137
.. doctest::
11381138
:hide:

Doc/library/shutil.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ Directory and files operations
473473
This is also applied when *cmd* is a path that contains a directory
474474
component::
475475

476-
>> shutil.which("C:\\Python33\\python")
476+
>>> shutil.which("C:\\Python33\\python")
477477
'C:\\Python33\\python.EXE'
478478

479479
.. versionadded:: 3.3

Doc/library/socket.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ Constants
498498
.. versionchanged:: 3.11
499499
NetBSD support was added.
500500

501+
.. versionchanged:: next
502+
Restored missing ``CAN_RAW_ERR_FILTER`` on Linux.
503+
501504
.. data:: CAN_BCM
502505
CAN_BCM_*
503506

Doc/library/stdtypes.rst

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,146 @@ expression support in the :mod:`re` module).
24562456
'-0042'
24572457

24582458

2459+
.. index::
2460+
single: ! formatted string literal
2461+
single: formatted string literals
2462+
single: ! f-string
2463+
single: f-strings
2464+
single: fstring
2465+
single: interpolated string literal
2466+
single: string; formatted literal
2467+
single: string; interpolated literal
2468+
single: {} (curly brackets); in formatted string literal
2469+
single: ! (exclamation mark); in formatted string literal
2470+
single: : (colon); in formatted string literal
2471+
single: = (equals); for help in debugging using string literals
2472+
2473+
Formatted String Literals (f-strings)
2474+
-------------------------------------
2475+
2476+
.. versionadded:: 3.6
2477+
.. versionchanged:: 3.7
2478+
The :keyword:`await` and :keyword:`async for` can be used in expressions
2479+
within f-strings.
2480+
.. versionchanged:: 3.8
2481+
Added the debugging operator (``=``)
2482+
.. versionchanged:: 3.12
2483+
Many restrictions on expressions within f-strings have been removed.
2484+
Notably, nested strings, comments, and backslashes are now permitted.
2485+
2486+
An :dfn:`f-string` (formally a :dfn:`formatted string literal`) is
2487+
a string literal that is prefixed with ``f`` or ``F``.
2488+
This type of string literal allows embedding arbitrary Python expressions
2489+
within *replacement fields*, which are delimited by curly brackets (``{}``).
2490+
These expressions are evaluated at runtime, similarly to :meth:`str.format`,
2491+
and are converted into regular :class:`str` objects.
2492+
For example:
2493+
2494+
.. doctest::
2495+
2496+
>>> who = 'nobody'
2497+
>>> nationality = 'Spanish'
2498+
>>> f'{who.title()} expects the {nationality} Inquisition!'
2499+
'Nobody expects the Spanish Inquisition!'
2500+
2501+
It is also possible to use a multi line f-string:
2502+
2503+
.. doctest::
2504+
2505+
>>> f'''This is a string
2506+
... on two lines'''
2507+
'This is a string\non two lines'
2508+
2509+
A single opening curly bracket, ``'{'``, marks a *replacement field* that
2510+
can contain any Python expression:
2511+
2512+
.. doctest::
2513+
2514+
>>> nationality = 'Spanish'
2515+
>>> f'The {nationality} Inquisition!'
2516+
'The Spanish Inquisition!'
2517+
2518+
To include a literal ``{`` or ``}``, use a double bracket:
2519+
2520+
.. doctest::
2521+
2522+
>>> x = 42
2523+
>>> f'{{x}} is {x}'
2524+
'{x} is 42'
2525+
2526+
Functions can also be used, and :ref:`format specifiers <formatstrings>`:
2527+
2528+
.. doctest::
2529+
2530+
>>> from math import sqrt
2531+
>>> f'√2 \N{ALMOST EQUAL TO} {sqrt(2):.5f}'
2532+
'√2 ≈ 1.41421'
2533+
2534+
Any non-string expression is converted using :func:`str`, by default:
2535+
2536+
.. doctest::
2537+
2538+
>>> from fractions import Fraction
2539+
>>> f'{Fraction(1, 3)}'
2540+
'1/3'
2541+
2542+
To use an explicit conversion, use the ``!`` (exclamation mark) operator,
2543+
followed by any of the valid formats, which are:
2544+
2545+
========== ==============
2546+
Conversion Meaning
2547+
========== ==============
2548+
``!a`` :func:`ascii`
2549+
``!r`` :func:`repr`
2550+
``!s`` :func:`str`
2551+
========== ==============
2552+
2553+
For example:
2554+
2555+
.. doctest::
2556+
2557+
>>> from fractions import Fraction
2558+
>>> f'{Fraction(1, 3)!s}'
2559+
'1/3'
2560+
>>> f'{Fraction(1, 3)!r}'
2561+
'Fraction(1, 3)'
2562+
>>> question = '¿Dónde está el Presidente?'
2563+
>>> print(f'{question!a}')
2564+
'\xbfD\xf3nde est\xe1 el Presidente?'
2565+
2566+
While debugging it may be helpful to see both the expression and its value,
2567+
by using the equals sign (``=``) after the expression.
2568+
This preserves spaces within the brackets, and can be used with a converter.
2569+
By default, the debugging operator uses the :func:`repr` (``!r``) conversion.
2570+
For example:
2571+
2572+
.. doctest::
2573+
2574+
>>> from fractions import Fraction
2575+
>>> calculation = Fraction(1, 3)
2576+
>>> f'{calculation=}'
2577+
'calculation=Fraction(1, 3)'
2578+
>>> f'{calculation = }'
2579+
'calculation = Fraction(1, 3)'
2580+
>>> f'{calculation = !s}'
2581+
'calculation = 1/3'
2582+
2583+
Once the output has been evaluated, it can be formatted using a
2584+
:ref:`format specifier <formatstrings>` following a colon (``':'``).
2585+
After the expression has been evaluated, and possibly converted to a string,
2586+
the :meth:`!__format__` method of the result is called with the format specifier,
2587+
or the empty string if no format specifier is given.
2588+
The formatted result is then used as the final value for the replacement field.
2589+
For example:
2590+
2591+
.. doctest::
2592+
2593+
>>> from fractions import Fraction
2594+
>>> f'{Fraction(1, 7):.6f}'
2595+
'0.142857'
2596+
>>> f'{Fraction(1, 7):_^+10}'
2597+
'___+1/7___'
2598+
24592599

24602600
.. _old-string-formatting:
24612601

Doc/using/cmdline.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ source.
7373

7474
.. audit-event:: cpython.run_command command cmdoption-c
7575

76+
.. versionchanged:: next
77+
*command* is automatically dedented before execution.
78+
7679
.. option:: -m <module-name>
7780

7881
Search :data:`sys.path` for the named module and execute its contents as

0 commit comments

Comments
 (0)
0