Skip to content

Commit ac8ff42

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix-functools_partial_repr_bug
2 parents a196de4 + 9b8d59c commit ac8ff42

Some content is hidden

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

41 files changed

+498
-297
lines changed

.github/workflows/tail-call.yml

Lines changed: 72 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
name: Tail calling interpreter
22
on:
33
pull_request:
4-
paths:
4+
paths: &paths
55
- '.github/workflows/tail-call.yml'
66
- 'Python/bytecodes.c'
77
- 'Python/ceval.c'
88
- 'Python/ceval_macros.h'
99
- 'Python/generated_cases.c.h'
1010
push:
11-
paths:
12-
- '.github/workflows/tail-call.yml'
13-
- 'Python/bytecodes.c'
14-
- 'Python/ceval.c'
15-
- 'Python/ceval_macros.h'
16-
- 'Python/generated_cases.c.h'
11+
paths: *paths
1712
workflow_dispatch:
1813

1914
permissions:
@@ -25,117 +20,109 @@ concurrency:
2520

2621
env:
2722
FORCE_COLOR: 1
23+
LLVM_VERSION: 21
2824

2925
jobs:
30-
tail-call:
26+
windows:
3127
name: ${{ matrix.target }}
3228
runs-on: ${{ matrix.runner }}
33-
timeout-minutes: 90
29+
timeout-minutes: 60
3430
strategy:
3531
fail-fast: false
3632
matrix:
37-
target:
38-
# Un-comment as we add support for more platforms for tail-calling interpreters.
39-
# - i686-pc-windows-msvc/msvc
40-
- x86_64-pc-windows-msvc/msvc
41-
- free-threading-msvc
42-
# - aarch64-pc-windows-msvc/msvc
43-
- x86_64-apple-darwin/clang
44-
- aarch64-apple-darwin/clang
45-
- x86_64-unknown-linux-gnu/gcc
46-
- aarch64-unknown-linux-gnu/gcc
47-
- free-threading
48-
llvm:
49-
- 20
5033
include:
51-
# - target: i686-pc-windows-msvc/msvc
52-
# architecture: Win32
53-
# runner: windows-2022
5434
- target: x86_64-pc-windows-msvc/msvc
5535
architecture: x64
5636
runner: windows-2025-vs2026
57-
- target: free-threading-msvc
37+
build_flags: ""
38+
run_tests: true
39+
- target: x86_64-pc-windows-msvc/msvc-free-threading
5840
architecture: x64
5941
runner: windows-2025-vs2026
60-
# - target: aarch64-pc-windows-msvc/msvc
61-
# architecture: ARM64
62-
# runner: windows-2022
63-
- target: x86_64-apple-darwin/clang
64-
architecture: x86_64
65-
runner: macos-15-intel
66-
- target: aarch64-apple-darwin/clang
67-
architecture: aarch64
68-
runner: macos-14
69-
- target: x86_64-unknown-linux-gnu/gcc
70-
architecture: x86_64
71-
runner: ubuntu-24.04
72-
- target: aarch64-unknown-linux-gnu/gcc
73-
architecture: aarch64
74-
runner: ubuntu-24.04-arm
75-
- target: free-threading
76-
architecture: x86_64
77-
runner: ubuntu-24.04
42+
build_flags: --disable-gil
43+
run_tests: false
7844
steps:
7945
- uses: actions/checkout@v6
8046
with:
8147
persist-credentials: false
8248
- uses: actions/setup-python@v6
8349
with:
8450
python-version: '3.11'
85-
86-
- name: Native Windows MSVC (release)
87-
if: runner.os == 'Windows' && matrix.architecture != 'ARM64' && matrix.target != 'free-threading-msvc'
51+
- name: Build
8852
shell: pwsh
8953
run: |
9054
$env:PlatformToolset = "v145"
91-
./PCbuild/build.bat --tail-call-interp -c Release -p ${{ matrix.architecture }}
92-
./PCbuild/rt.bat -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
93-
94-
# No tests:
95-
- name: Native Windows MSVC with free-threading (release)
96-
if: matrix.target == 'free-threading-msvc'
97-
shell: pwsh
98-
run: |
99-
$env:PlatformToolset = "v145"
100-
./PCbuild/build.bat --tail-call-interp --disable-gil -c Release -p ${{ matrix.architecture }}
101-
102-
# No tests (yet):
103-
- name: Emulated Windows Clang (release)
104-
if: runner.os == 'Windows' && matrix.architecture == 'ARM64'
55+
./PCbuild/build.bat --tail-call-interp ${{ matrix.build_flags }} -c Release -p ${{ matrix.architecture }}
56+
- name: Test
57+
if: matrix.run_tests
10558
shell: pwsh
10659
run: |
107-
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0
108-
$env:PlatformToolset = "clangcl"
109-
$env:LLVMToolsVersion = "${{ matrix.llvm }}.1.0"
110-
$env:LLVMInstallDir = "C:\Program Files\LLVM"
111-
./PCbuild/build.bat --tail-call-interp -p ${{ matrix.architecture }}
60+
./PCbuild/rt.bat -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
11261
113-
- name: Native macOS (release)
114-
if: runner.os == 'macOS'
62+
macos:
63+
name: ${{ matrix.target }}
64+
runs-on: ${{ matrix.runner }}
65+
timeout-minutes: 60
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
include:
70+
- target: x86_64-apple-darwin/clang
71+
runner: macos-15-intel
72+
- target: aarch64-apple-darwin/clang
73+
runner: macos-14
74+
steps:
75+
- uses: actions/checkout@v6
76+
with:
77+
persist-credentials: false
78+
- uses: actions/setup-python@v6
79+
with:
80+
python-version: '3.11'
81+
- name: Install dependencies
11582
run: |
11683
brew update
117-
brew install llvm@${{ matrix.llvm }}
84+
brew install llvm@${{ env.LLVM_VERSION }}
85+
- name: Build
86+
run: |
11887
export SDKROOT="$(xcrun --show-sdk-path)"
119-
export PATH="/usr/local/opt/llvm@${{ matrix.llvm }}/bin:$PATH"
120-
export PATH="/opt/homebrew/opt/llvm@${{ matrix.llvm }}/bin:$PATH"
121-
CC=clang-20 ./configure --with-tail-call-interp
88+
export PATH="/usr/local/opt/llvm@${{ env.LLVM_VERSION }}/bin:$PATH"
89+
export PATH="/opt/homebrew/opt/llvm@${{ env.LLVM_VERSION }}/bin:$PATH"
90+
CC=clang-${{ env.LLVM_VERSION }} ./configure --with-tail-call-interp
12291
make all --jobs 4
92+
- name: Test
93+
run: |
12394
./python.exe -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
12495
125-
- name: Native Linux (debug)
126-
if: runner.os == 'Linux' && matrix.target != 'free-threading'
96+
linux:
97+
name: ${{ matrix.target }}
98+
runs-on: ${{ matrix.runner }}
99+
timeout-minutes: 60
100+
strategy:
101+
fail-fast: false
102+
matrix:
103+
include:
104+
- target: x86_64-unknown-linux-gnu/gcc
105+
runner: ubuntu-24.04
106+
configure_flags: --with-pydebug
107+
- target: x86_64-unknown-linux-gnu/gcc-free-threading
108+
runner: ubuntu-24.04
109+
configure_flags: --disable-gil
110+
- target: aarch64-unknown-linux-gnu/gcc
111+
runner: ubuntu-24.04-arm
112+
configure_flags: --with-pydebug
113+
steps:
114+
- uses: actions/checkout@v6
115+
with:
116+
persist-credentials: false
117+
- uses: actions/setup-python@v6
118+
with:
119+
python-version: '3.11'
120+
- name: Build
127121
run: |
128-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
129-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
130-
CC=clang-20 ./configure --with-tail-call-interp --with-pydebug
122+
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ env.LLVM_VERSION }}
123+
export PATH="$(llvm-config-${{ env.LLVM_VERSION }} --bindir):$PATH"
124+
CC=clang-${{ env.LLVM_VERSION }} ./configure --with-tail-call-interp ${{ matrix.configure_flags }}
131125
make all --jobs 4
132-
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3
133-
134-
- name: Native Linux with free-threading (release)
135-
if: matrix.target == 'free-threading'
126+
- name: Test
136127
run: |
137-
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }}
138-
export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH"
139-
CC=clang-20 ./configure --with-tail-call-interp --disable-gil
140-
make all --jobs 4
141128
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3

Doc/library/stdtypes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,14 @@ expression support in the :mod:`re` module).
28702870
You can use :meth:`str.maketrans` to create a translation map from
28712871
character-to-character mappings in different formats.
28722872

2873+
The following example uses a mapping to replace ``'a'`` with ``'X'``,
2874+
``'b'`` with ``'Y'``, and delete ``'c'``:
2875+
2876+
.. doctest::
2877+
2878+
>>> 'abc123'.translate({ord('a'): 'X', ord('b'): 'Y', ord('c'): None})
2879+
'XY123'
2880+
28732881
See also the :mod:`codecs` module for a more flexible approach to custom
28742882
character mappings.
28752883

Lib/compileall.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
165165
stripdir = os.fspath(stripdir) if stripdir is not None else None
166166
name = os.path.basename(fullname)
167167

168+
# Without a cache_tag, we can only create legacy .pyc files. None of our
169+
# callers seem to expect this, so the best we can do is fail without raising
170+
if not legacy and sys.implementation.cache_tag is None:
171+
if not quiet:
172+
print("No cache tag is available to generate .pyc path for",
173+
repr(fullname))
174+
return False
175+
168176
dfile = None
169177

170178
if ddir is not None:

Lib/ensurepip/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
177177
args += ["--user"]
178178
if verbosity:
179179
args += ["-" + "v" * verbosity]
180+
if sys.implementation.cache_tag is None:
181+
args += ["--no-compile"]
180182

181183
return _run_pip([*args, "pip"], [os.fsdecode(tmp_wheel_path)])
182184

Lib/py_compile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ def main():
194194
else:
195195
filenames = args.filenames
196196
for filename in filenames:
197+
cfilename = (None if sys.implementation.cache_tag
198+
else f"{filename.rpartition('.')[0]}.pyc")
197199
try:
198-
compile(filename, doraise=True)
200+
compile(filename, cfilename, doraise=True)
199201
except PyCompileError as error:
200202
if args.quiet:
201203
parser.exit(1)

Lib/test/support/import_helper.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import importlib.machinery
55
import importlib.util
66
import os
7+
import py_compile
78
import shutil
89
import sys
910
import textwrap
@@ -49,20 +50,31 @@ def forget(modname):
4950
# combinations of PEP 3147/488 and legacy pyc files.
5051
unlink(source + 'c')
5152
for opt in ('', 1, 2):
52-
unlink(importlib.util.cache_from_source(source, optimization=opt))
53+
try:
54+
unlink(importlib.util.cache_from_source(source, optimization=opt))
55+
except NotImplementedError:
56+
pass
5357

5458

55-
def make_legacy_pyc(source):
59+
def make_legacy_pyc(source, allow_compile=False):
5660
"""Move a PEP 3147/488 pyc file to its legacy pyc location.
5761
5862
:param source: The file system path to the source file. The source file
59-
does not need to exist, however the PEP 3147/488 pyc file must exist.
63+
does not need to exist, however the PEP 3147/488 pyc file must exist or
64+
allow_compile must be set.
65+
:param allow_compile: If True, uses py_compile to create a .pyc if it does
66+
not exist. This should be passed as True if cache_tag may be None.
6067
:return: The file system path to the legacy pyc file.
6168
"""
62-
pyc_file = importlib.util.cache_from_source(source)
6369
assert source.endswith('.py')
6470
legacy_pyc = source + 'c'
65-
shutil.move(pyc_file, legacy_pyc)
71+
try:
72+
pyc_file = importlib.util.cache_from_source(source)
73+
shutil.move(pyc_file, legacy_pyc)
74+
except (FileNotFoundError, NotImplementedError):
75+
if not allow_compile:
76+
raise
77+
py_compile.compile(source, legacy_pyc, doraise=True)
6678
return legacy_pyc
6779

6880

Lib/test/test_argparse.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io
88
import operator
99
import os
10-
import py_compile
1110
import shutil
1211
import stat
1312
import sys
@@ -7162,9 +7161,8 @@ def make_script(self, dirname, basename, *, compiled=False):
71627161
script_name = script_helper.make_script(dirname, basename, self.source)
71637162
if not compiled:
71647163
return script_name
7165-
py_compile.compile(script_name, doraise=True)
7164+
pyc_file = import_helper.make_legacy_pyc(script_name, allow_compile=True)
71667165
os.remove(script_name)
7167-
pyc_file = import_helper.make_legacy_pyc(script_name)
71687166
return pyc_file
71697167

71707168
def make_zip_script(self, script_name, name_in_zip=None):

Lib/test/test_capi/test_import.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,10 @@ def check_executecode_pathnames(self, execute_code_func, object=False):
289289
self.check_executecodemodule(execute_code_func, NULL, pathname)
290290

291291
# Test NULL pathname and non-NULL cpathname
292-
pyc_filename = importlib.util.cache_from_source(__file__)
292+
try:
293+
pyc_filename = importlib.util.cache_from_source(__file__)
294+
except NotImplementedError:
295+
return
293296
py_filename = importlib.util.source_from_cache(pyc_filename)
294297
origin = self.check_executecodemodule(execute_code_func, NULL, pyc_filename)
295298
if not object:

0 commit comments

Comments
 (0)