Skip to content

Commit d339d8f

Browse files
authored
Merge branch 'main' into exec_doco
2 parents 22909cb + e924bb6 commit d339d8f

File tree

140 files changed

+4761
-1612
lines changed

Some content is hidden

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

140 files changed

+4761
-1612
lines changed

.github/workflows/mypy.yml

Lines changed: 1 addition & 1 deletion
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/reusable-docs.yml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 10 deletions
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/conf.py

Lines changed: 1 addition & 1 deletion
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/pending-removal-in-future.rst

Lines changed: 7 additions & 2 deletions
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

Lines changed: 47 additions & 0 deletions
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

Lines changed: 3 additions & 6 deletions
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

Doc/library/argparse.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ ArgumentParser objects
6161
formatter_class=argparse.HelpFormatter, \
6262
prefix_chars='-', fromfile_prefix_chars=None, \
6363
argument_default=None, conflict_handler='error', \
64-
add_help=True, allow_abbrev=True, exit_on_error=True)
64+
add_help=True, allow_abbrev=True, exit_on_error=True, \
65+
suggest_on_error=False)
6566

6667
Create a new :class:`ArgumentParser` object. All parameters should be passed
6768
as keyword arguments. Each parameter has its own more detailed description
@@ -103,6 +104,10 @@ ArgumentParser objects
103104
* exit_on_error_ - Determines whether or not ArgumentParser exits with
104105
error info when an error occurs. (default: ``True``)
105106

107+
* suggest_on_error_ - Enables suggestions for mistyped argument choices
108+
and subparser names (default: ``False``)
109+
110+
106111
.. versionchanged:: 3.5
107112
*allow_abbrev* parameter was added.
108113

@@ -559,6 +564,27 @@ If the user would like to catch errors manually, the feature can be enabled by s
559564

560565
.. versionadded:: 3.9
561566

567+
suggest_on_error
568+
^^^^^^^^^^^^^^^^
569+
570+
By default, when a user passes an invalid argument choice or subparser name,
571+
:class:`ArgumentParser` will exit with error info and list the permissible
572+
argument choices (if specified) or subparser names as part of the error message.
573+
574+
If the user would like to enable suggestions for mistyped argument choices and
575+
subparser names, the feature can be enabled by setting ``suggest_on_error`` to
576+
``True``. Note that this only applies for arguments when the choices specified
577+
are strings::
578+
579+
>>> parser = argparse.ArgumentParser(description='Process some integers.', suggest_on_error=True)
580+
>>> parser.add_argument('--action', choices=['sum', 'max'])
581+
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
582+
... help='an integer for the accumulator')
583+
>>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
584+
tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
585+
586+
.. versionadded:: 3.14
587+
562588

563589
The add_argument() method
564590
-------------------------
@@ -1868,6 +1894,10 @@ Argument groups
18681894
The function exists on the API by accident through inheritance and
18691895
will be removed in the future.
18701896

1897+
.. deprecated:: 3.14
1898+
Passing prefix_chars_ to :meth:`add_argument_group`
1899+
is now deprecated.
1900+
18711901

18721902
Mutual exclusion
18731903
^^^^^^^^^^^^^^^^

Doc/library/asyncio-dev.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ To handle signals the event loop must be
103103
run in the main thread.
104104

105105
The :meth:`loop.run_in_executor` method can be used with a
106-
:class:`concurrent.futures.ThreadPoolExecutor` to execute
106+
:class:`concurrent.futures.ThreadPoolExecutor` or
107+
:class:`~concurrent.futures.InterpreterPoolExecutor` to execute
107108
blocking code in a different OS thread without blocking the OS thread
108109
that the event loop runs in.
109110

@@ -128,7 +129,8 @@ if a function performs a CPU-intensive calculation for 1 second,
128129
all concurrent asyncio Tasks and IO operations would be delayed
129130
by 1 second.
130131

131-
An executor can be used to run a task in a different thread or even in
132+
An executor can be used to run a task in a different thread,
133+
including in a different interpreter, or even in
132134
a different process to avoid blocking the OS thread with the
133135
event loop. See the :meth:`loop.run_in_executor` method for more
134136
details.

Doc/library/asyncio-eventloop.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,12 @@ Executing code in thread or process pools
13051305
pool, cpu_bound)
13061306
print('custom process pool', result)
13071307

1308+
# 4. Run in a custom interpreter pool:
1309+
with concurrent.futures.InterpreterPoolExecutor() as pool:
1310+
result = await loop.run_in_executor(
1311+
pool, cpu_bound)
1312+
print('custom interpreter pool', result)
1313+
13081314
if __name__ == '__main__':
13091315
asyncio.run(main())
13101316

@@ -1329,7 +1335,8 @@ Executing code in thread or process pools
13291335

13301336
Set *executor* as the default executor used by :meth:`run_in_executor`.
13311337
*executor* must be an instance of
1332-
:class:`~concurrent.futures.ThreadPoolExecutor`.
1338+
:class:`~concurrent.futures.ThreadPoolExecutor`, which includes
1339+
:class:`~concurrent.futures.InterpreterPoolExecutor`.
13331340

13341341
.. versionchanged:: 3.11
13351342
*executor* must be an instance of

0 commit comments

Comments
 (0)