Skip to content

Commit 4b0a850

Browse files
committed
Merge branch 'main' into gh-115999-tlbc-call
2 parents 4c7837f + 26ff32b commit 4b0a850

File tree

157 files changed

+3180
-1372
lines changed

Some content is hidden

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

157 files changed

+3180
-1372
lines changed

.github/actionlint.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
self-hosted-runner:
2+
labels: ["ubuntu-24.04-aarch64", "windows-aarch64"]
3+
4+
config-variables: null
5+
6+
paths:
7+
.github/workflows/**/*.yml:
8+
ignore:
9+
- 1st argument of function call is not assignable
10+
- SC2(015|038|086|091|097|098|129|155)

.github/workflows/build.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,28 @@ jobs:
150150
needs: check_source
151151
if: fromJSON(needs.check_source.outputs.run_tests)
152152
strategy:
153+
fail-fast: false
153154
matrix:
155+
os:
156+
- windows-latest
154157
arch:
155-
- Win32
156-
- x64
157-
- arm64
158+
- x64
158159
free-threading:
159-
- false
160-
- true
160+
- false
161+
- true
162+
include:
163+
- os: windows-latest # FIXME(diegorusso): change to os: windows-aarch64
164+
arch: arm64
165+
free-threading: false
166+
- os: windows-latest # FIXME(diegorusso): change to os: windows-aarch64
167+
arch: arm64
168+
free-threading: true
169+
- os: windows-latest
170+
arch: Win32
171+
free-threading: false
161172
uses: ./.github/workflows/reusable-windows.yml
162173
with:
174+
os: ${{ matrix.os }}
163175
arch: ${{ matrix.arch }}
164176
free-threading: ${{ matrix.free-threading }}
165177

.github/workflows/reusable-ubuntu.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
os: [ubuntu-24.04]
23+
os: [ubuntu-24.04, ubuntu-24.04-aarch64]
2424
env:
2525
FORCE_COLOR: 1
2626
OPENSSL_VER: 3.0.15
@@ -82,11 +82,11 @@ jobs:
8282
- name: Build CPython out-of-tree
8383
if: ${{ inputs.free-threading }}
8484
working-directory: ${{ env.CPYTHON_BUILDDIR }}
85-
run: make -j4
85+
run: make -j
8686
- name: Build CPython out-of-tree (for compiler warning check)
8787
if: ${{ !inputs.free-threading}}
8888
working-directory: ${{ env.CPYTHON_BUILDDIR }}
89-
run: set -o pipefail; make -j4 --output-sync 2>&1 | tee compiler_output_ubuntu.txt
89+
run: set -o pipefail; make -j --output-sync 2>&1 | tee compiler_output_ubuntu.txt
9090
- name: Display build info
9191
working-directory: ${{ env.CPYTHON_BUILDDIR }}
9292
run: make pythoninfo

.github/workflows/reusable-windows.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Reusable Windows
33
on:
44
workflow_call:
55
inputs:
6+
os:
7+
description: OS to run on
8+
required: true
9+
type: string
610
arch:
711
description: CPU architecture
812
required: true
@@ -19,10 +23,8 @@ env:
1923
2024
jobs:
2125
build:
22-
name: >-
23-
build${{ inputs.arch != 'arm64' && ' and test' || '' }}
24-
(${{ inputs.arch }})
25-
runs-on: windows-latest
26+
name: 'build and test (${{ inputs.arch }})'
27+
runs-on: ${{ inputs.os }}
2628
timeout-minutes: 60
2729
steps:
2830
- uses: actions/checkout@v4
@@ -31,17 +33,17 @@ jobs:
3133
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
3234
- name: Build CPython
3335
run: >-
34-
.\PCbuild\build.bat
36+
.\\PCbuild\\build.bat
3537
-e -d -v
3638
-p ${{ inputs.arch }}
3739
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
38-
- name: Display build info
40+
- name: Display build info # FIXME(diegorusso): remove the `if`
3941
if: inputs.arch != 'arm64'
40-
run: .\python.bat -m test.pythoninfo
41-
- name: Tests
42+
run: .\\python.bat -m test.pythoninfo
43+
- name: Tests # FIXME(diegorusso): remove the `if`
4244
if: inputs.arch != 'arm64'
4345
run: >-
44-
.\PCbuild\rt.bat
46+
.\\PCbuild\\rt.bat
4547
-p ${{ inputs.arch }}
4648
-d -q --fast-ci
4749
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}

.pre-commit-config.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ repos:
5757
- id: check-github-workflows
5858

5959
- repo: https://github.com/rhysd/actionlint
60-
rev: v1.7.3
60+
rev: v1.7.4
6161
hooks:
6262
- id: actionlint
63-
args: [
64-
-ignore=1st argument of function call is not assignable,
65-
-ignore=SC2(015|038|086|091|097|098|129|155),
66-
]
6763

6864
- repo: https://github.com/sphinx-contrib/sphinx-lint
6965
rev: v1.0.0

Doc/c-api/init.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,11 @@ function. You can create and destroy them using the following functions:
17381738
.check_multi_interp_extensions = 1,
17391739
.gil = PyInterpreterConfig_OWN_GIL,
17401740
};
1741-
PyThreadState *tstate = Py_NewInterpreterFromConfig(&config);
1741+
PyThreadState *tstate = NULL;
1742+
PyStatus status = Py_NewInterpreterFromConfig(&tstate, &config);
1743+
if (PyStatus_Exception(status)) {
1744+
Py_ExitStatusException(status);
1745+
}
17421746
17431747
Note that the config is used only briefly and does not get modified.
17441748
During initialization the config's values are converted into various
@@ -2466,7 +2470,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24662470
24672471
{
24682472
PyCriticalSection2 _py_cs2;
2469-
PyCriticalSection_Begin2(&_py_cs2, (PyObject*)(a), (PyObject*)(b))
2473+
PyCriticalSection2_Begin(&_py_cs2, (PyObject*)(a), (PyObject*)(b))
24702474
24712475
In the default build, this macro expands to ``{``.
24722476
@@ -2478,7 +2482,7 @@ code triggered by the finalizer blocks and calls :c:func:`PyEval_SaveThread`.
24782482
24792483
In the free-threaded build, this macro expands to::
24802484
2481-
PyCriticalSection_End2(&_py_cs2);
2485+
PyCriticalSection2_End(&_py_cs2);
24822486
}
24832487
24842488
In the default build, this macro expands to ``}``.

Doc/c-api/init_config.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Python Initialization Configuration
77
***********************************
88

9+
.. _pyconfig_api:
10+
911
PyConfig C API
1012
==============
1113

@@ -1592,6 +1594,8 @@ The ``__PYVENV_LAUNCHER__`` environment variable is used to set
15921594
:c:member:`PyConfig.base_executable`.
15931595
15941596
1597+
.. _pyinitconfig_api:
1598+
15951599
PyInitConfig C API
15961600
==================
15971601

Doc/library/argparse.rst

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ arguments it contains. The default message can be overridden with the
192192
The ``%(prog)s`` format specifier is available to fill in the program name in
193193
your usage messages.
194194

195+
When a custom usage message is specified for the main parser, you may also want to
196+
consider passing the ``prog`` argument to :meth:`~ArgumentParser.add_subparsers`
197+
or the ``prog`` and the ``usage`` arguments to
198+
:meth:`~_SubParsersAction.add_parser`, to ensure consistent command prefixes and
199+
usage information across subparsers.
200+
195201

196202
.. _description:
197203

@@ -583,6 +589,14 @@ are strings::
583589
>>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
584590
tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
585591

592+
If you're writing code that needs to be compatible with older Python versions
593+
and want to opportunistically use ``suggest_on_error`` when it's available, you
594+
can set it as an attribute after initializing the parser instead of using the
595+
keyword argument::
596+
597+
>>> parser = argparse.ArgumentParser(description='Process some integers.')
598+
>>> parser.suggest_on_error = True
599+
586600
.. versionadded:: 3.14
587601

588602

@@ -801,7 +815,8 @@ Only actions that consume command-line arguments (e.g. ``'store'``,
801815

802816
The recommended way to create a custom action is to extend :class:`Action`,
803817
overriding the :meth:`!__call__` method and optionally the :meth:`!__init__` and
804-
:meth:`!format_usage` methods.
818+
:meth:`!format_usage` methods. You can also register custom actions using the
819+
:meth:`~ArgumentParser.register` method and reference them by their registered name.
805820

806821
An example of a custom action::
807822

@@ -1020,10 +1035,11 @@ necessary type-checking and type conversions to be performed.
10201035
If the type_ keyword is used with the default_ keyword, the type converter
10211036
is only applied if the default is a string.
10221037

1023-
The argument to ``type`` can be any callable that accepts a single string.
1038+
The argument to ``type`` can be a callable that accepts a single string or
1039+
the name of a registered type (see :meth:`~ArgumentParser.register`)
10241040
If the function raises :exc:`ArgumentTypeError`, :exc:`TypeError`, or
10251041
:exc:`ValueError`, the exception is caught and a nicely formatted error
1026-
message is displayed. No other exception types are handled.
1042+
message is displayed. Other exception types are not handled.
10271043

10281044
Common built-in types and functions can be used as type converters:
10291045

@@ -1808,6 +1824,10 @@ Sub-commands
18081824
.. versionchanged:: 3.7
18091825
New *required* keyword-only parameter.
18101826

1827+
.. versionchanged:: 3.14
1828+
Subparser's *prog* is no longer affected by a custom usage message in
1829+
the main parser.
1830+
18111831

18121832
FileType objects
18131833
^^^^^^^^^^^^^^^^
@@ -1906,11 +1926,10 @@ Argument groups
19061926
Note that any arguments not in your user-defined groups will end up back
19071927
in the usual "positional arguments" and "optional arguments" sections.
19081928

1909-
.. versionchanged:: 3.11
1910-
Calling :meth:`add_argument_group` on an argument group is deprecated.
1911-
This feature was never supported and does not always work correctly.
1912-
The function exists on the API by accident through inheritance and
1913-
will be removed in the future.
1929+
.. deprecated-removed:: 3.11 3.14
1930+
Calling :meth:`add_argument_group` on an argument group now raises an
1931+
exception. This nesting was never supported, often failed to work
1932+
correctly, and was unintentionally exposed through inheritance.
19141933

19151934
.. deprecated:: 3.14
19161935
Passing prefix_chars_ to :meth:`add_argument_group`
@@ -1973,11 +1992,11 @@ Mutual exclusion
19731992
--foo FOO foo help
19741993
--bar BAR bar help
19751994

1976-
.. versionchanged:: 3.11
1977-
Calling :meth:`add_argument_group` or :meth:`add_mutually_exclusive_group`
1978-
on a mutually exclusive group is deprecated. These features were never
1979-
supported and do not always work correctly. The functions exist on the
1980-
API by accident through inheritance and will be removed in the future.
1995+
.. deprecated-removed:: 3.11 3.14
1996+
Calling :meth:`add_argument_group` or :meth:`add_mutually_exclusive_group`
1997+
on a mutually exclusive group now raises an exception. This nesting was
1998+
never supported, often failed to work correctly, and was unintentionally
1999+
exposed through inheritance.
19812000

19822001

19832002
Parser defaults
@@ -2163,6 +2182,34 @@ Intermixed parsing
21632182
.. versionadded:: 3.7
21642183

21652184

2185+
Registering custom types or actions
2186+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2187+
2188+
.. method:: ArgumentParser.register(registry_name, value, object)
2189+
2190+
Sometimes it's desirable to use a custom string in error messages to provide
2191+
more user-friendly output. In these cases, :meth:`!register` can be used to
2192+
register custom actions or types with a parser and allow you to reference the
2193+
type by their registered name instead of their callable name.
2194+
2195+
The :meth:`!register` method accepts three arguments - a *registry_name*,
2196+
specifying the internal registry where the object will be stored (e.g.,
2197+
``action``, ``type``), *value*, which is the key under which the object will
2198+
be registered, and object, the callable to be registered.
2199+
2200+
The following example shows how to register a custom type with a parser::
2201+
2202+
>>> import argparse
2203+
>>> parser = argparse.ArgumentParser()
2204+
>>> parser.register('type', 'hexadecimal integer', lambda s: int(s, 16))
2205+
>>> parser.add_argument('--foo', type='hexadecimal integer')
2206+
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None, default=None, type='hexadecimal integer', choices=None, required=False, help=None, metavar=None, deprecated=False)
2207+
>>> parser.parse_args(['--foo', '0xFA'])
2208+
Namespace(foo=250)
2209+
>>> parser.parse_args(['--foo', '1.2'])
2210+
usage: PROG [-h] [--foo FOO]
2211+
PROG: error: argument --foo: invalid 'hexadecimal integer' value: '1.2'
2212+
21662213
Exceptions
21672214
----------
21682215

0 commit comments

Comments
 (0)