Skip to content

Commit 8663204

Browse files
Merge branch 'main' into pythongh-125560
2 parents c379c48 + 03f9264 commit 8663204

File tree

194 files changed

+6262
-2219
lines changed

Some content is hidden

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

194 files changed

+6262
-2219
lines changed

.github/workflows/build.yml

+46-9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,50 @@ jobs:
4040
if: fromJSON(needs.check_source.outputs.run-docs)
4141
uses: ./.github/workflows/reusable-docs.yml
4242

43+
check_autoconf_regen:
44+
name: 'Check if Autoconf files are up to date'
45+
# Don't use ubuntu-latest but a specific version to make the job
46+
# reproducible: to get the same tools versions (autoconf, aclocal, ...)
47+
runs-on: ubuntu-24.04
48+
container:
49+
image: ghcr.io/python/autoconf:2024.10.11.11293396815
50+
timeout-minutes: 60
51+
needs: check_source
52+
if: needs.check_source.outputs.run_tests == 'true'
53+
steps:
54+
- name: Install Git
55+
run: |
56+
apt install git -yq
57+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
58+
- uses: actions/checkout@v4
59+
with:
60+
fetch-depth: 1
61+
- name: Runner image version
62+
run: echo "IMAGE_VERSION=${ImageVersion}" >> $GITHUB_ENV
63+
- name: Check Autoconf and aclocal versions
64+
run: |
65+
grep "Generated by GNU Autoconf 2.71" configure
66+
grep "aclocal 1.16.5" aclocal.m4
67+
grep -q "runstatedir" configure
68+
grep -q "PKG_PROG_PKG_CONFIG" aclocal.m4
69+
- name: Regenerate autoconf files
70+
# Same command used by Tools/build/regen-configure.sh ($AUTORECONF)
71+
run: autoreconf -ivf -Werror
72+
- name: Check for changes
73+
run: |
74+
git add -u
75+
changes=$(git status --porcelain)
76+
# Check for changes in regenerated files
77+
if test -n "$changes"; then
78+
echo "Generated files not up to date."
79+
echo "Perhaps you forgot to run make regen-all or build.bat --regen. ;)"
80+
echo "configure files must be regenerated with a specific version of autoconf."
81+
echo "$changes"
82+
echo ""
83+
git diff --staged || true
84+
exit 1
85+
fi
86+
4387
check_generated_files:
4488
name: 'Check if generated files are up to date'
4589
# Don't use ubuntu-latest but a specific version to make the job
@@ -69,19 +113,10 @@ jobs:
69113
uses: hendrikmuhs/[email protected]
70114
with:
71115
save: false
72-
- name: Check Autoconf and aclocal versions
73-
run: |
74-
grep "Generated by GNU Autoconf 2.71" configure
75-
grep "aclocal 1.16.5" aclocal.m4
76-
grep -q "runstatedir" configure
77-
grep -q "PKG_PROG_PKG_CONFIG" aclocal.m4
78116
- name: Configure CPython
79117
run: |
80118
# Build Python with the libpython dynamic library
81119
./configure --config-cache --with-pydebug --enable-shared
82-
- name: Regenerate autoconf files
83-
# Same command used by Tools/build/regen-configure.sh ($AUTORECONF)
84-
run: autoreconf -ivf -Werror
85120
- name: Build CPython
86121
run: |
87122
make -j4 regen-all
@@ -501,6 +536,7 @@ jobs:
501536
needs:
502537
- check_source # Transitive dependency, needed to access `run_tests` value
503538
- check-docs
539+
- check_autoconf_regen
504540
- check_generated_files
505541
- build_macos
506542
- build_ubuntu
@@ -536,6 +572,7 @@ jobs:
536572
${{
537573
needs.check_source.outputs.run_tests != 'true'
538574
&& '
575+
check_autoconf_regen,
539576
check_generated_files,
540577
build_macos,
541578
build_ubuntu,

.github/workflows/mypy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- uses: actions/checkout@v4
5454
- uses: actions/setup-python@v5
5555
with:
56-
python-version: "3.11"
56+
python-version: "3.13"
5757
cache: pip
5858
cache-dependency-path: Tools/requirements-dev.txt
5959
- run: pip install -r Tools/requirements-dev.txt

.github/workflows/posix-deps-apt.sh

-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#!/bin/sh
22
apt-get update
33

4-
# autoconf-archive is needed by autoreconf (check_generated_files job)
54
apt-get -yq install \
65
build-essential \
76
pkg-config \
8-
autoconf-archive \
97
ccache \
108
gdb \
119
lcov \

.github/workflows/reusable-docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: 'Set up Python'
8585
uses: actions/setup-python@v5
8686
with:
87-
python-version: '3.12' # known to work with Sphinx 6.2.1
87+
python-version: '3.13' # known to work with Sphinx 7.2.6
8888
cache: 'pip'
8989
cache-dependency-path: 'Doc/requirements-oldest-sphinx.txt'
9090
- name: 'Install build dependencies'

Doc/c-api/contextvars.rst

+4-10
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,10 @@ Context object management functions:
123123
124124
Enumeration of possible context object watcher events:
125125
126-
- ``Py_CONTEXT_EVENT_ENTER``: A context has been entered, causing the
127-
:term:`current context` to switch to it. The object passed to the watch
128-
callback is the now-current :class:`contextvars.Context` object. Each
129-
enter event will eventually have a corresponding exit event for the same
130-
context object after any subsequently entered contexts have themselves been
131-
exited.
132-
- ``Py_CONTEXT_EVENT_EXIT``: A context is about to be exited, which will
133-
cause the :term:`current context` to switch back to what it was before the
134-
context was entered. The object passed to the watch callback is the
135-
still-current :class:`contextvars.Context` object.
126+
- ``Py_CONTEXT_SWITCHED``: The :term:`current context` has switched to a
127+
different context. The object passed to the watch callback is the
128+
now-current :class:`contextvars.Context` object, or None if no context is
129+
current.
136130
137131
.. versionadded:: 3.14
138132

Doc/c-api/init.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ Process-wide parameters
625625
returned string points into static storage; the caller should not modify its
626626
value. This corresponds to the :makevar:`prefix` variable in the top-level
627627
:file:`Makefile` and the :option:`--prefix` argument to the :program:`configure`
628-
script at build time. The value is available to Python code as ``sys.prefix``.
628+
script at build time. The value is available to Python code as ``sys.base_prefix``.
629629
It is only useful on Unix. See also the next function.
630630
631631
This function should not be called before :c:func:`Py_Initialize`, otherwise
@@ -635,7 +635,8 @@ Process-wide parameters
635635
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
636636
637637
.. deprecated-removed:: 3.13 3.15
638-
Get :data:`sys.prefix` instead.
638+
Get :data:`sys.base_prefix` instead, or :data:`sys.prefix` if
639+
:ref:`virtual environments <venv-def>` need to be handled.
639640
640641
641642
.. c:function:: wchar_t* Py_GetExecPrefix()
@@ -648,7 +649,8 @@ Process-wide parameters
648649
should not modify its value. This corresponds to the :makevar:`exec_prefix`
649650
variable in the top-level :file:`Makefile` and the ``--exec-prefix``
650651
argument to the :program:`configure` script at build time. The value is
651-
available to Python code as ``sys.exec_prefix``. It is only useful on Unix.
652+
available to Python code as ``sys.base_exec_prefix``. It is only useful on
653+
Unix.
652654
653655
Background: The exec-prefix differs from the prefix when platform dependent
654656
files (such as executables and shared libraries) are installed in a different
@@ -679,7 +681,8 @@ Process-wide parameters
679681
It now returns ``NULL`` if called before :c:func:`Py_Initialize`.
680682
681683
.. deprecated-removed:: 3.13 3.15
682-
Get :data:`sys.exec_prefix` instead.
684+
Get :data:`sys.base_exec_prefix` instead, or :data:`sys.exec_prefix` if
685+
:ref:`virtual environments <venv-def>` need to be handled.
683686
684687
685688
.. c:function:: wchar_t* Py_GetProgramFullPath()
@@ -2418,7 +2421,7 @@ Example usage::
24182421
24192422
In the above example, :c:macro:`Py_SETREF` calls :c:macro:`Py_DECREF`, which
24202423
can call arbitrary code through an object's deallocation function. The critical
2421-
section API avoids potentital deadlocks due to reentrancy and lock ordering
2424+
section API avoids potential deadlocks due to reentrancy and lock ordering
24222425
by allowing the runtime to temporarily suspend the critical section if the
24232426
code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24242427

Doc/c-api/long.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
511511
free(bignum);
512512
513513
*flags* is either ``-1`` (``Py_ASNATIVEBYTES_DEFAULTS``) to select defaults
514-
that behave most like a C cast, or a combintation of the other flags in
514+
that behave most like a C cast, or a combination of the other flags in
515515
the table below.
516516
Note that ``-1`` cannot be combined with other flags.
517517

Doc/c-api/monitoring.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ would typically correspond to a python function.
147147
148148
The ``version`` argument is a pointer to a value which should be allocated
149149
by the user together with ``state_array`` and initialized to 0,
150-
and then set only by :c:func:`!PyMonitoring_EnterScope` itelf. It allows this
150+
and then set only by :c:func:`!PyMonitoring_EnterScope` itself. It allows this
151151
function to determine whether event states have changed since the previous call,
152152
and to return quickly if they have not.
153153

Doc/c-api/typeobj.rst

+13-11
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,19 @@ and :c:data:`PyType_Type` effectively act as defaults.)
682682
Py_DECREF(tp);
683683
}
684684
685+
.. warning::
686+
687+
In a garbage collected Python, :c:member:`!tp_dealloc` may be called from
688+
any Python thread, not just the thread which created the object (if the
689+
object becomes part of a refcount cycle, that cycle might be collected by
690+
a garbage collection on any thread). This is not a problem for Python
691+
API calls, since the thread on which :c:member:`!tp_dealloc` is called
692+
will own the Global Interpreter Lock (GIL). However, if the object being
693+
destroyed in turn destroys objects from some other C or C++ library, care
694+
should be taken to ensure that destroying those objects on the thread
695+
which called :c:member:`!tp_dealloc` will not violate any assumptions of
696+
the library.
697+
685698

686699
**Inheritance:**
687700

@@ -2109,17 +2122,6 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21092122
PyErr_Restore(error_type, error_value, error_traceback);
21102123
}
21112124

2112-
Also, note that, in a garbage collected Python,
2113-
:c:member:`~PyTypeObject.tp_dealloc` may be called from
2114-
any Python thread, not just the thread which created the object (if the object
2115-
becomes part of a refcount cycle, that cycle might be collected by a garbage
2116-
collection on any thread). This is not a problem for Python API calls, since
2117-
the thread on which tp_dealloc is called will own the Global Interpreter Lock
2118-
(GIL). However, if the object being destroyed in turn destroys objects from some
2119-
other C or C++ library, care should be taken to ensure that destroying those
2120-
objects on the thread which called tp_dealloc will not violate any assumptions
2121-
of the library.
2122-
21232125
**Inheritance:**
21242126

21252127
This field is inherited by subtypes.

Doc/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
highlight_language = 'python3'
9191

9292
# Minimum version of sphinx required
93-
needs_sphinx = '6.2.1'
93+
needs_sphinx = '7.2.6'
9494

9595
# Create table of contents entries for domain objects (e.g. functions, classes,
9696
# attributes, etc.). Default is True.

Doc/deprecations/c-api-pending-removal-in-3.15.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Pending removal in Python 3.15
1313
* :c:func:`PySys_ResetWarnOptions`:
1414
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead.
1515
* :c:func:`Py_GetExecPrefix`:
16-
Get :data:`sys.exec_prefix` instead.
16+
Get :data:`sys.base_exec_prefix` and :data:`sys.exec_prefix` instead.
1717
* :c:func:`Py_GetPath`:
1818
Get :data:`sys.path` instead.
1919
* :c:func:`Py_GetPrefix`:
20-
Get :data:`sys.prefix` instead.
20+
Get :data:`sys.base_prefix` and :data:`sys.prefix` instead.
2121
* :c:func:`Py_GetProgramFullPath`:
2222
Get :data:`sys.executable` instead.
2323
* :c:func:`Py_GetProgramName`:

Doc/deprecations/pending-removal-in-future.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ Pending removal in future versions
44
The following APIs will be removed in the future,
55
although there is currently no date scheduled for their removal.
66

7-
* :mod:`argparse`: Nesting argument groups and nesting mutually exclusive
8-
groups are deprecated.
7+
* :mod:`argparse`:
8+
9+
* Nesting argument groups and nesting mutually exclusive
10+
groups are deprecated.
11+
* Passing the undocumented keyword argument *prefix_chars* to
12+
:meth:`~argparse.ArgumentParser.add_argument_group` is now
13+
deprecated.
914

1015
* :mod:`array`'s ``'u'`` format code (:gh:`57281`)
1116

Doc/howto/argparse.rst

+47
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,53 @@ translated messages.
841841

842842
To translate your own strings in the :mod:`argparse` output, use :mod:`gettext`.
843843

844+
Custom type converters
845+
======================
846+
847+
The :mod:`argparse` module allows you to specify custom type converters for
848+
your command-line arguments. This allows you to modify user input before it's
849+
stored in the :class:`argparse.Namespace`. This can be useful when you need to
850+
pre-process the input before it is used in your program.
851+
852+
When using a custom type converter, you can use any callable that takes a
853+
single string argument (the argument value) and returns the converted value.
854+
However, if you need to handle more complex scenarios, you can use a custom
855+
action class with the **action** parameter instead.
856+
857+
For example, let's say you want to handle arguments with different prefixes and
858+
process them accordingly::
859+
860+
import argparse
861+
862+
parser = argparse.ArgumentParser(prefix_chars='-+')
863+
864+
parser.add_argument('-a', metavar='<value>', action='append',
865+
type=lambda x: ('-', x))
866+
parser.add_argument('+a', metavar='<value>', action='append',
867+
type=lambda x: ('+', x))
868+
869+
args = parser.parse_args()
870+
print(args)
871+
872+
Output:
873+
874+
.. code-block:: shell-session
875+
876+
$ python prog.py -a value1 +a value2
877+
Namespace(a=[('-', 'value1'), ('+', 'value2')])
878+
879+
In this example, we:
880+
881+
* Created a parser with custom prefix characters using the ``prefix_chars``
882+
parameter.
883+
884+
* Defined two arguments, ``-a`` and ``+a``, which used the ``type`` parameter to
885+
create custom type converters to store the value in a tuple with the prefix.
886+
887+
Without the custom type converters, the arguments would have treated the ``-a``
888+
and ``+a`` as the same argument, which would have been undesirable. By using custom
889+
type converters, we were able to differentiate between the two arguments.
890+
844891
Conclusion
845892
==========
846893

Doc/library/_thread.rst

+3-6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ Lock objects have the following methods:
187187
.. versionchanged:: 3.2
188188
Lock acquires can now be interrupted by signals on POSIX.
189189

190+
.. versionchanged:: 3.14
191+
Lock acquires can now be interrupted by signals on Windows.
192+
190193

191194
.. method:: lock.release()
192195

@@ -219,12 +222,6 @@ In addition to these methods, lock objects can also be used via the
219222
* Calling :func:`sys.exit` or raising the :exc:`SystemExit` exception is
220223
equivalent to calling :func:`_thread.exit`.
221224

222-
* It is platform-dependent whether the :meth:`~threading.Lock.acquire` method
223-
on a lock can be interrupted (so that the :exc:`KeyboardInterrupt` exception
224-
will happen immediately, rather than only after the lock has been acquired or
225-
the operation has timed out). It can be interrupted on POSIX, but not on
226-
Windows.
227-
228225
* When the main thread exits, it is system defined whether the other threads
229226
survive. On most systems, they are killed without executing
230227
:keyword:`try` ... :keyword:`finally` clauses or executing object

0 commit comments

Comments
 (0)