Skip to content

Commit

Permalink
Merge branch '3.13' into backport-addb225-3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
gpshead authored Nov 24, 2024
2 parents f8bb55a + 9dbce9f commit ecda65f
Show file tree
Hide file tree
Showing 51 changed files with 869 additions and 404 deletions.
37 changes: 26 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

check_abi:
name: 'Check if the ABI has changed'
runs-on: ubuntu-22.04
runs-on: ubuntu-22.04 # 24.04 causes spurious errors
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
steps:
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
steps:
- name: Install Git
run: |
apt install git -yq
apt update && apt install git -yq
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
name: 'Check if generated files are up to date'
# Don't use ubuntu-latest but a specific version to make the job
# reproducible: to get the same tools versions (autoconf, aclocal, ...)
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
timeout-minutes: 60
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
Expand Down Expand Up @@ -193,16 +193,28 @@ jobs:
needs: check_source
if: fromJSON(needs.check_source.outputs.run_tests)
strategy:
fail-fast: false
matrix:
os:
- windows-latest
arch:
- Win32
- x64
- arm64
- x64
free-threading:
- false
- true
- false
- true
include:
- os: windows-latest # FIXME(diegorusso): change to os: windows-aarch64
arch: arm64
free-threading: false
- os: windows-latest # FIXME(diegorusso): change to os: windows-aarch64
arch: arm64
free-threading: true
- os: windows-latest
arch: Win32
free-threading: false
uses: ./.github/workflows/reusable-windows.yml
with:
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
free-threading: ${{ matrix.free-threading }}

Expand Down Expand Up @@ -280,7 +292,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-24.04]
openssl_ver: [3.0.15, 3.1.7, 3.2.3, 3.3.2]
env:
OPENSSL_VER: ${{ matrix.openssl_ver }}
Expand Down Expand Up @@ -340,7 +352,7 @@ jobs:

test_hypothesis:
name: "Hypothesis tests on Ubuntu"
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
timeout-minutes: 60
needs: check_source
if: needs.check_source.outputs.run_tests == 'true' && needs.check_source.outputs.run_hypothesis == 'true'
Expand Down Expand Up @@ -453,10 +465,13 @@ jobs:

build_asan:
name: 'Address sanitizer'
runs-on: ubuntu-22.04
runs-on: ${{ matrix.os }}
timeout-minutes: 60
needs: check_source
if: needs.check_source.outputs.run_tests == 'true'
strategy:
matrix:
os: [ubuntu-24.04]
env:
OPENSSL_VER: 3.0.15
PYTHONSTRICTEXTENSIONBUILD: 1
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/posix-deps-apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ apt-get -yq install \
libgdbm-dev \
libgdbm-compat-dev \
liblzma-dev \
libmpdec-dev \
libncurses5-dev \
libreadline6-dev \
libsqlite3-dev \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
jobs:
build_tsan_reusable:
name: 'Thread sanitizer'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-24.04, ubuntu-24.04-aarch64]
env:
FORCE_COLOR: 1
OPENSSL_VER: 3.0.15
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
- name: Build CPython out-of-tree
working-directory: ${{ env.CPYTHON_BUILDDIR }}
run: make -j4
run: make -j
- name: Display build info
working-directory: ${{ env.CPYTHON_BUILDDIR }}
run: make pythoninfo
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build_wasi_reusable:
name: 'build and test'
timeout-minutes: 60
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
WASMTIME_VERSION: 22.0.0
WASI_SDK_VERSION: 24
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/reusable-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Reusable Windows
on:
workflow_call:
inputs:
os:
description: OS to run on
required: true
type: string
arch:
description: CPU architecture
required: true
Expand All @@ -19,10 +23,8 @@ env:
jobs:
build:
name: >-
build${{ inputs.arch != 'arm64' && ' and test' || '' }}
(${{ inputs.arch }})
runs-on: windows-latest
name: 'build and test (${{ inputs.arch }})'
runs-on: ${{ inputs.os }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
Expand All @@ -31,17 +33,17 @@ jobs:
run: echo "::add-matcher::.github/problem-matchers/msvc.json"
- name: Build CPython
run: >-
.\PCbuild\build.bat
.\\PCbuild\\build.bat
-e -d -v
-p ${{ inputs.arch }}
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
- name: Display build info
- name: Display build info # FIXME(diegorusso): remove the `if`
if: inputs.arch != 'arm64'
run: .\python.bat -m test.pythoninfo
- name: Tests
run: .\\python.bat -m test.pythoninfo
- name: Tests # FIXME(diegorusso): remove the `if`
if: inputs.arch != 'arm64'
run: >-
.\PCbuild\rt.bat
.\\PCbuild\\rt.bat
-p ${{ inputs.arch }}
-d -q --fast-ci
${{ fromJSON(inputs.free-threading) && '--disable-gil' || '' }}
6 changes: 5 additions & 1 deletion Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,11 @@ function. You can create and destroy them using the following functions:
.check_multi_interp_extensions = 1,
.gil = PyInterpreterConfig_OWN_GIL,
};
PyThreadState *tstate = Py_NewInterpreterFromConfig(&config);
PyThreadState *tstate = NULL;
PyStatus status = Py_NewInterpreterFromConfig(&tstate, &config);
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
Note that the config is used only briefly and does not get modified.
During initialization the config's values are converted into various
Expand Down
36 changes: 33 additions & 3 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ Only actions that consume command-line arguments (e.g. ``'store'``,

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

An example of a custom action::

Expand Down Expand Up @@ -973,10 +974,11 @@ necessary type-checking and type conversions to be performed.
If the type_ keyword is used with the default_ keyword, the type converter
is only applied if the default is a string.

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

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

Expand Down Expand Up @@ -2103,6 +2105,34 @@ Intermixed parsing
.. versionadded:: 3.7


Registering custom types or actions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. method:: ArgumentParser.register(registry_name, value, object)

Sometimes it's desirable to use a custom string in error messages to provide
more user-friendly output. In these cases, :meth:`!register` can be used to
register custom actions or types with a parser and allow you to reference the
type by their registered name instead of their callable name.

The :meth:`!register` method accepts three arguments - a *registry_name*,
specifying the internal registry where the object will be stored (e.g.,
``action``, ``type``), *value*, which is the key under which the object will
be registered, and object, the callable to be registered.

The following example shows how to register a custom type with a parser::

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.register('type', 'hexadecimal integer', lambda s: int(s, 16))
>>> parser.add_argument('--foo', type='hexadecimal integer')
_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)
>>> parser.parse_args(['--foo', '0xFA'])
Namespace(foo=250)
>>> parser.parse_args(['--foo', '1.2'])
usage: PROG [-h] [--foo FOO]
PROG: error: argument --foo: invalid 'hexadecimal integer' value: '1.2'

Exceptions
----------

Expand Down
Loading

0 comments on commit ecda65f

Please sign in to comment.