Skip to content

Commit ee8f268

Browse files
committed
Merge branch 'main' into error-on-unused-cached
2 parents ceb1659 + 8303d32 commit ee8f268

File tree

175 files changed

+1765
-1102
lines changed

Some content is hidden

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

175 files changed

+1765
-1102
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV WASI_SDK_VERSION=21
66
ENV WASI_SDK_PATH=/opt/wasi-sdk
77

88
ENV WASMTIME_HOME=/opt/wasmtime
9-
ENV WASMTIME_VERSION=18.0.3
9+
ENV WASMTIME_VERSION=22.0.0
1010
ENV WASMTIME_CPU_ARCH=x86_64
1111

1212
RUN dnf -y --nodocs --setopt=install_weak_deps=False install /usr/bin/{blurb,clang,curl,git,ln,tar,xz} 'dnf-command(builddep)' && \

.github/workflows/build.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,24 @@ jobs:
179179
run: make check-c-globals
180180

181181
build_windows:
182-
name: 'Windows'
182+
name: >-
183+
Windows
184+
${{ fromJSON(matrix.free-threading) && '(free-threading)' || '' }}
183185
needs: check_source
184-
if: needs.check_source.outputs.run_tests == 'true'
185-
uses: ./.github/workflows/reusable-windows.yml
186-
187-
build_windows_free_threading:
188-
name: 'Windows (free-threading)'
189-
needs: check_source
190-
if: needs.check_source.outputs.run_tests == 'true'
186+
if: fromJSON(needs.check_source.outputs.run_tests)
187+
strategy:
188+
matrix:
189+
arch:
190+
- Win32
191+
- x64
192+
- arm64
193+
free-threading:
194+
- false
195+
- true
191196
uses: ./.github/workflows/reusable-windows.yml
192197
with:
193-
free-threading: true
198+
arch: ${{ matrix.arch }}
199+
free-threading: ${{ matrix.free-threading }}
194200

195201
build_macos:
196202
name: 'macOS'
@@ -393,7 +399,7 @@ jobs:
393399
path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/
394400
key: hypothesis-database-${{ github.head_ref || github.run_id }}
395401
restore-keys: |
396-
- hypothesis-database-
402+
hypothesis-database-
397403
- name: "Run tests"
398404
working-directory: ${{ env.CPYTHON_BUILDDIR }}
399405
run: |
@@ -556,7 +562,6 @@ jobs:
556562
- build_ubuntu_ssltests
557563
- build_wasi
558564
- build_windows
559-
- build_windows_free_threading
560565
- test_hypothesis
561566
- build_asan
562567
- build_tsan
@@ -592,7 +597,6 @@ jobs:
592597
build_ubuntu_ssltests,
593598
build_wasi,
594599
build_windows,
595-
build_windows_free_threading,
596600
build_asan,
597601
build_tsan,
598602
build_tsan_free_threading,

.github/workflows/reusable-wasi.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
timeout-minutes: 60
1212
runs-on: ubuntu-22.04
1313
env:
14-
WASMTIME_VERSION: 18.0.3
14+
WASMTIME_VERSION: 22.0.0
1515
WASI_SDK_VERSION: 21
1616
WASI_SDK_PATH: /opt/wasi-sdk
1717
CROSS_BUILD_PYTHON: cross-build/build
@@ -20,9 +20,9 @@ jobs:
2020
- uses: actions/checkout@v4
2121
# No problem resolver registered as one doesn't currently exist for Clang.
2222
- name: "Install wasmtime"
23-
uses: jcbhmr/setup-wasmtime@v2
23+
uses: bytecodealliance/actions/wasmtime/setup@v1
2424
with:
25-
wasmtime-version: ${{ env.WASMTIME_VERSION }}
25+
version: ${{ env.WASMTIME_VERSION }}
2626
- name: "Restore WASI SDK"
2727
id: cache-wasi-sdk
2828
uses: actions/cache@v4
@@ -50,8 +50,10 @@ jobs:
5050
uses: actions/cache@v4
5151
with:
5252
path: ${{ env.CROSS_BUILD_PYTHON }}/config.cache
53-
# Include env.pythonLocation in key to avoid changes in environment when setup-python updates Python
54-
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ inputs.config_hash }}-${{ env.pythonLocation }}
53+
# Include env.pythonLocation in key to avoid changes in environment when setup-python updates Python.
54+
# Include the hash of `Tools/wasm/wasi.py` as it may change the environment variables.
55+
# (Make sure to keep the key in sync with the other config.cache step below.)
56+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ env.WASI_SDK_VERSION }}-${{ env.WASMTIME_VERSION }}-${{ inputs.config_hash }}-${{ hashFiles('Tools/wasm/wasi.py') }}-${{ env.pythonLocation }}
5557
- name: "Configure build Python"
5658
run: python3 Tools/wasm/wasi.py configure-build-python -- --config-cache --with-pydebug
5759
- name: "Make build Python"
@@ -60,8 +62,8 @@ jobs:
6062
uses: actions/cache@v4
6163
with:
6264
path: ${{ env.CROSS_BUILD_WASI }}/config.cache
63-
# Include env.pythonLocation in key to avoid changes in environment when setup-python updates Python
64-
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-wasi-sdk-${{ env.WASI_SDK_VERSION }}-${{ inputs.config_hash }}-${{ env.pythonLocation }}
65+
# Should be kept in sync with the other config.cache step above.
66+
key: ${{ github.job }}-${{ runner.os }}-${{ env.IMAGE_VERSION }}-${{ env.WASI_SDK_VERSION }}-${{ env.WASMTIME_VERSION }}-${{ inputs.config_hash }}-${{ hashFiles('Tools/wasm/wasi.py') }}-${{ env.pythonLocation }}
6567
- name: "Configure host"
6668
# `--with-pydebug` inferred from configure-build-python
6769
run: python3 Tools/wasm/wasi.py configure-host -- --config-cache
Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,45 @@
11
on:
22
workflow_call:
33
inputs:
4+
arch:
5+
description: CPU architecture
6+
required: true
7+
type: string
48
free-threading:
9+
description: Whether to use no-GIL mode
510
required: false
611
type: boolean
712
default: false
813

9-
jobs:
10-
build_win32:
11-
name: 'build and test (x86)'
12-
runs-on: windows-latest
13-
timeout-minutes: 60
14-
env:
15-
IncludeUwp: 'true'
16-
steps:
17-
- uses: actions/checkout@v4
18-
- name: Build CPython
19-
run: .\PCbuild\build.bat -e -d -v -p Win32 ${{ inputs.free-threading && '--disable-gil' || '' }}
20-
- name: Display build info
21-
run: .\python.bat -m test.pythoninfo
22-
- name: Tests
23-
run: .\PCbuild\rt.bat -p Win32 -d -q --fast-ci ${{ inputs.free-threading && '--disable-gil' || '' }}
14+
env:
15+
IncludeUwp: >-
16+
true
2417
25-
build_win_amd64:
26-
name: 'build and test (x64)'
18+
jobs:
19+
build:
20+
name: >-
21+
build${{ inputs.arch != 'arm64' && ' and test' || '' }}
22+
(${{ inputs.arch }})
2723
runs-on: windows-latest
2824
timeout-minutes: 60
29-
env:
30-
IncludeUwp: 'true'
3125
steps:
3226
- uses: actions/checkout@v4
3327
- name: Register MSVC problem matcher
28+
if: inputs.arch != 'Win32'
3429
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
3530
- name: Build CPython
36-
run: .\PCbuild\build.bat -e -d -v -p x64 ${{ inputs.free-threading && '--disable-gil' || '' }}
31+
run: >-
32+
.\PCbuild\build.bat
33+
-e -d -v
34+
-p ${{ inputs.arch }}
35+
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
3736
- name: Display build info
37+
if: inputs.arch != 'arm64'
3838
run: .\python.bat -m test.pythoninfo
3939
- name: Tests
40-
run: .\PCbuild\rt.bat -p x64 -d -q --fast-ci ${{ inputs.free-threading && '--disable-gil' || '' }}
41-
42-
build_win_arm64:
43-
name: 'build (arm64)'
44-
runs-on: windows-latest
45-
timeout-minutes: 60
46-
env:
47-
IncludeUwp: 'true'
48-
steps:
49-
- uses: actions/checkout@v4
50-
- name: Register MSVC problem matcher
51-
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
52-
- name: Build CPython
53-
run: .\PCbuild\build.bat -e -d -v -p arm64 ${{ inputs.free-threading && '--disable-gil' || '' }}
40+
if: inputs.arch != 'arm64'
41+
run: >-
42+
.\PCbuild\rt.bat
43+
-p ${{ inputs.arch }}
44+
-d -q --fast-ci
45+
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}

Doc/c-api/cell.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Cell objects are not likely to be useful elsewhere.
3939
4040
.. c:function:: PyObject* PyCell_Get(PyObject *cell)
4141
42-
Return the contents of the cell *cell*.
42+
Return the contents of the cell *cell*, which can be ``NULL``.
43+
If *cell* is not a cell object, returns ``NULL`` with an exception set.
4344
4445
4546
.. c:function:: PyObject* PyCell_GET(PyObject *cell)
@@ -52,8 +53,10 @@ Cell objects are not likely to be useful elsewhere.
5253
5354
Set the contents of the cell object *cell* to *value*. This releases the
5455
reference to any current content of the cell. *value* may be ``NULL``. *cell*
55-
must be non-``NULL``; if it is not a cell object, ``-1`` will be returned. On
56-
success, ``0`` will be returned.
56+
must be non-``NULL``.
57+
58+
On success, return ``0``.
59+
If *cell* is not a cell object, set an exception and return ``-1``.
5760
5861
5962
.. c:function:: void PyCell_SET(PyObject *cell, PyObject *value)

Doc/c-api/module.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Module Objects
4343
to ``None``); the caller is responsible for providing a :attr:`__file__`
4444
attribute.
4545
46+
Return ``NULL`` with an exception set on error.
47+
4648
.. versionadded:: 3.3
4749
4850
.. versionchanged:: 3.4
@@ -265,6 +267,8 @@ of the following two module creation functions:
265267
API version *module_api_version*. If that version does not match the version
266268
of the running interpreter, a :exc:`RuntimeWarning` is emitted.
267269
270+
Return ``NULL`` with an exception set on error.
271+
268272
.. note::
269273
270274
Most uses of this function should be using :c:func:`PyModule_Create`
@@ -461,6 +465,8 @@ objects dynamically. Note that both ``PyModule_FromDefAndSpec`` and
461465
If that version does not match the version of the running interpreter,
462466
a :exc:`RuntimeWarning` is emitted.
463467
468+
Return ``NULL`` with an exception set on error.
469+
464470
.. note::
465471
466472
Most uses of this function should be using :c:func:`PyModule_FromDefAndSpec`
@@ -511,7 +517,7 @@ state:
511517
512518
On success, return ``0``. On error, raise an exception and return ``-1``.
513519
514-
Return ``NULL`` if *value* is ``NULL``. It must be called with an exception
520+
Return ``-1`` if *value* is ``NULL``. It must be called with an exception
515521
raised in this case.
516522
517523
Example usage::
@@ -601,23 +607,24 @@ state:
601607
.. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
602608
603609
Add an integer constant to *module* as *name*. This convenience function can be
604-
used from the module's initialization function. Return ``-1`` on error, ``0`` on
605-
success.
610+
used from the module's initialization function.
611+
Return ``-1`` with an exception set on error, ``0`` on success.
606612
607613
608614
.. c:function:: int PyModule_AddStringConstant(PyObject *module, const char *name, const char *value)
609615
610616
Add a string constant to *module* as *name*. This convenience function can be
611617
used from the module's initialization function. The string *value* must be
612-
``NULL``-terminated. Return ``-1`` on error, ``0`` on success.
618+
``NULL``-terminated.
619+
Return ``-1`` with an exception set on error, ``0`` on success.
613620
614621
615622
.. c:macro:: PyModule_AddIntMacro(module, macro)
616623
617624
Add an int constant to *module*. The name and the value are taken from
618625
*macro*. For example ``PyModule_AddIntMacro(module, AF_INET)`` adds the int
619626
constant *AF_INET* with the value of *AF_INET* to *module*.
620-
Return ``-1`` on error, ``0`` on success.
627+
Return ``-1`` with an exception set on error, ``0`` on success.
621628
622629
623630
.. c:macro:: PyModule_AddStringMacro(module, macro)
@@ -630,7 +637,7 @@ state:
630637
The type object is finalized by calling internally :c:func:`PyType_Ready`.
631638
The name of the type object is taken from the last component of
632639
:c:member:`~PyTypeObject.tp_name` after dot.
633-
Return ``-1`` on error, ``0`` on success.
640+
Return ``-1`` with an exception set on error, ``0`` on success.
634641
635642
.. versionadded:: 3.9
636643
@@ -643,7 +650,7 @@ state:
643650
import machinery assumes the module does not support running without the
644651
GIL. This function is only available in Python builds configured with
645652
:option:`--disable-gil`.
646-
Return ``-1`` on error, ``0`` on success.
653+
Return ``-1`` with an exception set on error, ``0`` on success.
647654
648655
.. versionadded:: 3.13
649656
@@ -682,14 +689,14 @@ since multiple such modules can be created from a single definition.
682689
683690
The caller must hold the GIL.
684691
685-
Return 0 on success or -1 on failure.
692+
Return ``-1`` with an exception set on error, ``0`` on success.
686693
687694
.. versionadded:: 3.3
688695
689696
.. c:function:: int PyState_RemoveModule(PyModuleDef *def)
690697
691698
Removes the module object created from *def* from the interpreter state.
692-
Return 0 on success or -1 on failure.
699+
Return ``-1`` with an exception set on error, ``0`` on success.
693700
694701
The caller must hold the GIL.
695702

Doc/c-api/slice.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Slice Objects
2323
Return a new slice object with the given values. The *start*, *stop*, and
2424
*step* parameters are used as the values of the slice object attributes of
2525
the same names. Any of the values may be ``NULL``, in which case the
26-
``None`` will be used for the corresponding attribute. Return ``NULL`` if
26+
``None`` will be used for the corresponding attribute.
27+
28+
Return ``NULL`` with an exception set if
2729
the new object could not be allocated.
2830
2931
@@ -52,7 +54,7 @@ Slice Objects
5254
of bounds indices are clipped in a manner consistent with the handling of
5355
normal slices.
5456
55-
Returns ``0`` on success and ``-1`` on error with exception set.
57+
Return ``0`` on success and ``-1`` on error with an exception set.
5658
5759
.. note::
5860
This function is considered not safe for resizable sequences.
@@ -95,7 +97,7 @@ Slice Objects
9597
``PY_SSIZE_T_MIN`` to ``PY_SSIZE_T_MIN``, and silently boost the step
9698
values less than ``-PY_SSIZE_T_MAX`` to ``-PY_SSIZE_T_MAX``.
9799
98-
Return ``-1`` on error, ``0`` on success.
100+
Return ``-1`` with an exception set on error, ``0`` on success.
99101
100102
.. versionadded:: 3.6.1
101103

Doc/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@
272272
('c:data', 'PyExc_UnicodeWarning'),
273273
('c:data', 'PyExc_UserWarning'),
274274
('c:data', 'PyExc_Warning'),
275+
# Undocumented public C macros
276+
('c:macro', 'Py_BUILD_ASSERT'),
277+
('c:macro', 'Py_BUILD_ASSERT_EXPR'),
275278
# Do not error nit-picky mode builds when _SubParsersAction.add_parser cannot
276279
# be resolved, as the method is currently undocumented. For context, see
277280
# https://github.com/python/cpython/pull/103289.

Doc/faq/programming.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,11 +1741,31 @@ but effective way to define class private variables. Any identifier of the form
17411741
is textually replaced with ``_classname__spam``, where ``classname`` is the
17421742
current class name with any leading underscores stripped.
17431743

1744-
This doesn't guarantee privacy: an outside user can still deliberately access
1745-
the "_classname__spam" attribute, and private values are visible in the object's
1746-
``__dict__``. Many Python programmers never bother to use private variable
1747-
names at all.
1744+
The identifier can be used unchanged within the class, but to access it outside
1745+
the class, the mangled name must be used:
17481746

1747+
.. code-block:: python
1748+
1749+
class A:
1750+
def __one(self):
1751+
return 1
1752+
def two(self):
1753+
return 2 * self.__one()
1754+
1755+
class B(A):
1756+
def three(self):
1757+
return 3 * self._A__one()
1758+
1759+
four = 4 * A()._A__one()
1760+
1761+
In particular, this does not guarantee privacy since an outside user can still
1762+
deliberately access the private attribute; many Python programmers never bother
1763+
to use private variable names at all.
1764+
1765+
.. seealso::
1766+
1767+
The :ref:`private name mangling specifications <private-name-mangling>`
1768+
for details and special cases.
17491769

17501770
My class defines __del__ but it is not called when I delete the object.
17511771
-----------------------------------------------------------------------

0 commit comments

Comments
 (0)