Skip to content

Commit 1760121

Browse files
Merge remote-tracking branch 'upstream/3.13' into backport-c8ca336-3.13
2 parents ecadf50 + b871e39 commit 1760121

150 files changed

Lines changed: 3214 additions & 951 deletions

File tree

Some content is hidden

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

.github/workflows/reusable-context.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ jobs:
8686
|| ''
8787
}}
8888
89-
- name: 'Downgrade Git'
90-
# Temporarily downgrade to 2.43 until 2.55 is in the runner image,
91-
# to avoid "fatal: shallow file has changed since we read it" bug.
92-
# See https://github.com/python/cpython/issues/151365.
93-
if: github.event_name == 'pull_request'
94-
run: |
95-
sudo apt-get install -y --allow-downgrades 'git=1:2.43.*' 'git-man=1:2.43.*'
96-
git --version
97-
9889
# Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721
9990
- name: Fetch commits to get branch diff
10091
if: github.event_name == 'pull_request'

.github/workflows/reusable-docs.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ jobs:
4747
&& github.event.pull_request.head.sha
4848
|| ''
4949
}}
50-
- name: 'Downgrade Git'
51-
# Temporarily downgrade to 2.43 until 2.55 is in the runner image,
52-
# to avoid "fatal: shallow file has changed since we read it" bug.
53-
# See https://github.com/python/cpython/issues/151365.
54-
if: github.event_name == 'pull_request'
55-
run: |
56-
sudo apt-get install -y --allow-downgrades 'git=1:2.43.*' 'git-man=1:2.43.*'
57-
git --version
5850
# Adapted from https://github.com/actions/checkout/issues/520#issuecomment-1167205721
5951
- name: 'Fetch commits to get branch diff'
6052
if: github.event_name == 'pull_request'
@@ -94,6 +86,9 @@ jobs:
9486
--fail-if-regression \
9587
--fail-if-improved \
9688
--fail-if-new-news-nit
89+
- name: 'Build list of changes'
90+
run: |
91+
make -C Doc/ PYTHON=../python changes
9792
9893
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
9994
doctest:

Doc/howto/curses.rst

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,18 @@ the next subsection.
298298

299299
The :meth:`~curses.window.addstr` method takes a Python string or
300300
bytestring as the value to be displayed. The contents of bytestrings
301-
are sent to the terminal as-is. Strings are encoded to bytes using
302-
the value of the window's :attr:`~window.encoding` attribute; this defaults to
303-
the default system encoding as returned by :func:`locale.getencoding`.
301+
are sent to the terminal as-is.
302+
On a build without wide-character support strings are encoded
303+
using the value of the window's :attr:`~window.encoding` attribute;
304+
this defaults to the default system encoding
305+
as returned by :func:`locale.getencoding`.
304306

305307
The :meth:`~curses.window.addch` methods take a character, which can be
306308
either a string of length 1, a bytestring of length 1, or an integer.
307309

308-
Constants are provided for extension characters; these constants are
309-
integers greater than 255. For example, :const:`ACS_PLMINUS` is a +/-
310+
Constants are provided for the characters of the terminal's alternate
311+
character set.
312+
For example, :const:`ACS_PLMINUS` is a +/-
310313
symbol, and :const:`ACS_ULCORNER` is the upper left corner of a box
311314
(handy for drawing borders). You can also use the appropriate Unicode
312315
character.
@@ -320,11 +323,11 @@ won't be distracting; it can be confusing to have the cursor blinking at some
320323
apparently random location.
321324

322325
If your application doesn't need a blinking cursor at all, you can
323-
call ``curs_set(False)`` to make it invisible. For compatibility
324-
with older curses versions, there's a ``leaveok(bool)`` function
325-
that's a synonym for :func:`~curses.curs_set`. When *bool* is true, the
326-
curses library will attempt to suppress the flashing cursor, and you
327-
won't need to worry about leaving it in odd locations.
326+
call ``curs_set(False)`` to make it invisible.
327+
The window method :meth:`~curses.window.leaveok` does something different:
328+
when its argument is true,
329+
curses leaves the cursor wherever the last update put it,
330+
instead of moving it back to the window's cursor position.
328331

329332

330333
Attributes and Color
@@ -430,40 +433,48 @@ The C curses library offers only very simple input mechanisms. Python's
430433
:mod:`curses` module adds a basic text-input widget. (Other libraries
431434
such as :pypi:`Urwid` have more extensive collections of widgets.)
432435

433-
There are two methods for getting input from a window:
436+
There are three methods for getting input from a window:
434437

435-
* :meth:`~curses.window.getch` refreshes the screen and then waits for
438+
* :meth:`~curses.window.get_wch` refreshes the screen and then waits for
436439
the user to hit a key, displaying the key if :func:`~curses.echo` has been
437440
called earlier. You can optionally specify a coordinate to which
438441
the cursor should be moved before pausing.
439442

440-
* :meth:`~curses.window.getkey` does the same thing but converts the
441-
integer to a string. Individual characters are returned as
442-
1-character strings, and special keys such as function keys return
443-
longer strings containing a key name such as ``KEY_UP`` or ``^G``.
443+
* :meth:`~curses.window.getch` does the same thing but returns the code of
444+
the key instead of a character.
445+
With ncurses this is a single byte of the key's encoding in the current
446+
locale, so a character encoded with several bytes takes several calls,
447+
one byte per call.
448+
449+
* :meth:`~curses.window.getkey` does the same as :meth:`!getch` but returns
450+
a string:
451+
an ordinary key as a 1-character string,
452+
and a special key as its name, such as ``KEY_UP``.
444453

445454
It's possible to not wait for the user using the
446455
:meth:`~curses.window.nodelay` window method. After ``nodelay(True)``,
447-
:meth:`!getch` and :meth:`!getkey` for the window become
448-
non-blocking. To signal that no input is ready, :meth:`!getch` returns
449-
``curses.ERR`` (a value of -1) and :meth:`!getkey` raises an exception.
456+
the reads for the window become non-blocking.
457+
To signal that no input is ready,
458+
:meth:`!get_wch` and :meth:`!getkey` raise an exception,
459+
and :meth:`!getch` returns ``-1``.
450460
There's also a :func:`~curses.halfdelay` function, which can be used to (in
451-
effect) set a timer on each :meth:`!getch`; if no input becomes
461+
effect) set a timer on each read; if no input becomes
452462
available within a specified delay (measured in tenths of a second),
453-
curses raises an exception.
463+
the read fails the same way.
454464

455-
The :meth:`!getch` method returns an integer; if it's between 0 and 255, it
456-
represents the ASCII code of the key pressed. Values greater than 255 are
457-
special keys such as Page Up, Home, or the cursor keys. You can compare the
458-
value returned to constants such as :const:`curses.KEY_PPAGE`,
465+
Special keys such as Page Up, Home, or the cursor keys are returned by all
466+
three as one of the :ref:`KEY_* constants <curses-key-constants>`,
467+
all larger than 255.
468+
You can compare the value returned to constants such as
469+
:const:`curses.KEY_PPAGE`,
459470
:const:`curses.KEY_HOME`, or :const:`curses.KEY_LEFT`. The main loop of
460471
your program may look something like this::
461472

462473
while True:
463-
c = stdscr.getch()
464-
if c == ord('p'):
474+
c = stdscr.get_wch()
475+
if c == 'p':
465476
PrintDocument()
466-
elif c == ord('q'):
477+
elif c == 'q':
467478
break # Exit the while loop
468479
elif c == curses.KEY_HOME:
469480
x = y = 0
@@ -475,15 +486,16 @@ conversion functions that take either integer or 1-character-string arguments
475486
and return the same type. For example, :func:`curses.ascii.ctrl` returns the
476487
control character corresponding to its argument.
477488

478-
There's also a method to retrieve an entire string,
489+
There's also a method to retrieve an entire line,
479490
:meth:`~curses.window.getstr`. It isn't used very often, because its
480491
functionality is quite limited; the only editing keys available are
481-
the backspace key and the Enter key, which terminates the string. It
482-
can optionally be limited to a fixed number of characters. ::
492+
the erase and kill characters, and the Enter key, which terminates the line.
493+
It returns a bytes object,
494+
and can optionally be limited to a fixed number of bytes. ::
483495

484496
curses.echo() # Enable echoing of characters
485497

486-
# Get a 15-character string, with the cursor on the top line
498+
# Get a line of at most 15 bytes, with the cursor on the top line
487499
s = stdscr.getstr(0,0, 15)
488500

489501
The :mod:`curses.textpad` module supplies a text box that supports an

Doc/howto/logging-cookbook.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3912,7 +3912,7 @@ subclassed handler which looks something like this::
39123912

39133913
You'll need to be familiar with RFC 5424 to fully understand the above code, and it
39143914
may be that you have slightly different needs (e.g. for how you pass structural data
3915-
to the log). Nevertheless, the above should be adaptable to your speciric needs. With
3915+
to the log). Nevertheless, the above should be adaptable to your specific needs. With
39163916
the above handler, you'd pass structured data using something like this::
39173917

39183918
sd = {

Doc/howto/mro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ prescription:
189189
the tail of any of the other lists, then add it to the linearization
190190
of C and remove it from the lists in the merge, otherwise look at the
191191
head of the next list and take it, if it is a good head. Then repeat
192-
the operation until all the class are removed or it is impossible to
192+
the operation until all the classes are removed or it is impossible to
193193
find good heads. In this case, it is impossible to construct the
194194
merge, Python 2.3 will refuse to create the class C and will raise an
195195
exception.*

Doc/library/argparse.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ how the command-line arguments should be handled. The supplied actions are:
734734
>>> parser.parse_args(['-vvv'])
735735
Namespace(verbose=3)
736736

737-
Note, the *default* will be ``None`` unless explicitly set to *0*.
737+
Unless explicitly set, the *default* will be ``None``. If the default
738+
value is a non-zero number, the count starts from that number rather
739+
than from zero.
738740

739741
* ``'help'`` - This prints a complete help message for all the options in the
740742
current parser and then exits. By default a help action is automatically

Doc/library/asyncio-task.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ and reliable way to wait for all tasks in the group to finish.
347347
The signature matches that of :func:`asyncio.create_task`.
348348
If the task group is inactive (e.g. not yet entered,
349349
already finished, or in the process of shutting down),
350-
we will close the given ``coro``.
350+
we will close the given ``coro`` and raise :exc:`RuntimeError`.
351351

352352
.. versionchanged:: 3.13
353353

Doc/library/atexit.rst

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,68 @@
99

1010
--------------
1111

12-
The :mod:`atexit` module defines functions to register and unregister cleanup
13-
functions. Functions thus registered are automatically executed upon normal
14-
interpreter termination. :mod:`atexit` runs these functions in the *reverse*
15-
order in which they were registered; if you register ``A``, ``B``, and ``C``,
16-
at interpreter termination time they will be run in the order ``C``, ``B``,
17-
``A``.
18-
19-
**Note:** The functions registered via this module are not called when the
12+
The :mod:`!atexit` module defines functions to register and unregister
13+
:dfn:`exit handlers`: functions that are automatically executed
14+
"at exit", that is, upon normal program termination (for instance,
15+
if :func:`sys.exit` is called or the main module's execution completes)
16+
or, more generally, upon :term:`interpreter shutdown`.
17+
18+
At exit, all registered exit handlers are called
19+
in the *reverse* order in which they were registered.
20+
If you register ``A``, ``B``, and ``C``, at interpreter shutdown time they
21+
will be run in the order ``C``, ``B``, ``A``.
22+
The assumption is that lower level modules will normally be imported before
23+
higher level modules and thus must be cleaned up later.
24+
25+
If an exception is raised during execution of an exit handler, a traceback is
26+
printed (unless :exc:`SystemExit` is raised) and the exception information is
27+
saved. After all exit handlers have had a chance to run, the last exception to
28+
be raised is re-raised.
29+
30+
In programs that use multiple interpreters, each interpreter has its own stack
31+
of exit handlers, which are executed when the interpreter shuts down
32+
(for example, with the C API function :c:func:`Py_EndInterpreter`).
33+
Registration functions in this module only affect the interpreter they are
34+
called from.
35+
36+
**Note:** Exit handlers are not called when the
2037
program is killed by a signal not handled by Python, when a Python fatal
2138
internal error is detected, or when :func:`os._exit` is called.
2239

2340
**Note:** The effect of registering or unregistering functions from within
2441
a cleanup function is undefined.
2542

26-
.. versionchanged:: 3.7
27-
When used with C-API subinterpreters, registered functions
28-
are local to the interpreter they were registered in.
43+
.. warning::
44+
When writing exit handlers, especially in C API extensions, keep in mind
45+
that other exit handlers may still run arbitrary Python code after you
46+
clean up.
47+
Such code should succeed or fail with an exception, rather than crash.
2948

30-
.. function:: register(func, *args, **kwargs)
49+
.. versionchanged:: 3.12
50+
Attempts to start a new thread or :func:`os.fork` a new process
51+
in an exit handler now leads to :exc:`RuntimeError`.
52+
Previously, this could cause race conditions between the main Python
53+
runtime thread freeing thread states while internal :mod:`threading`
54+
routines or the new process try to use that state, which could lead to
55+
crashes rather than clean shutdown.
3156

32-
Register *func* as a function to be executed at termination. Any optional
33-
arguments that are to be passed to *func* must be passed as arguments to
34-
:func:`register`. It is possible to register the same function and arguments
35-
more than once.
57+
.. versionchanged:: 3.7
58+
When used with subinterpreters, registered functions
59+
are local to the interpreter they were registered in.
3660

37-
At normal program termination (for instance, if :func:`sys.exit` is called or
38-
the main module's execution completes), all functions registered are called in
39-
last in, first out order. The assumption is that lower level modules will
40-
normally be imported before higher level modules and thus must be cleaned up
41-
later.
61+
.. function:: register(func, *args, **kwargs)
4262

43-
If an exception is raised during execution of the exit handlers, a traceback is
44-
printed (unless :exc:`SystemExit` is raised) and the exception information is
45-
saved. After all exit handlers have had a chance to run, the last exception to
46-
be raised is re-raised.
63+
Register *func* as an exit handler.
64+
Any optional arguments that are to be passed to *func* must be passed as
65+
arguments to :func:`register`.
66+
It is possible to register the same function and arguments more than once.
4767

4868
This function returns *func*, which makes it possible to use it as a
4969
decorator.
5070

51-
.. warning::
52-
Starting new threads or calling :func:`os.fork` from a registered
53-
function can lead to race condition between the main Python
54-
runtime thread freeing thread states while internal :mod:`threading`
55-
routines or the new process try to use that state. This can lead to
56-
crashes rather than clean shutdown.
57-
58-
.. versionchanged:: 3.12
59-
Attempts to start a new thread or :func:`os.fork` a new process
60-
in a registered function now leads to :exc:`RuntimeError`.
61-
6271
.. function:: unregister(func)
6372

64-
Remove *func* from the list of functions to be run at interpreter shutdown.
73+
Remove *func* from the list of exit handlers.
6574
:func:`unregister` silently does nothing if *func* was not previously
6675
registered. If *func* has been registered more than once, every occurrence
6776
of that function in the :mod:`atexit` call stack will be removed. Equality

Doc/library/colorsys.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spaces, the coordinates are all between 0 and 1.
2121
.. seealso::
2222

2323
More information about color spaces can be found at
24-
https://poynton.ca/ColorFAQ.html and
24+
https://www.poynton.ca/pdf/ColourFAQ.pdf and
2525
https://www.cambridgeincolour.com/tutorials/color-spaces.htm.
2626

2727
The :mod:`colorsys` module defines the following functions:

Doc/library/curses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,8 @@ Window objects
971971

972972
.. attribute:: window.encoding
973973

974-
Encoding used to encode method arguments (Unicode strings and characters).
974+
Encoding used to encode the string arguments of the methods and to decode
975+
their results on a build without wide-character support.
975976
The encoding attribute is inherited from the parent window when a subwindow
976977
is created, for example with :meth:`window.subwin`.
977978
By default, current locale encoding is used (see :func:`locale.getencoding`).

0 commit comments

Comments
 (0)