Skip to content

Commit 3fd7d3b

Browse files
committed
Merge branch 'master' into overflows-in-array-e/156864
2 parents 9617a72 + 7b4364d commit 3fd7d3b

28 files changed

Lines changed: 687 additions & 174 deletions

.claude/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../AGENTS.md

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ Python/frozen_modules/MANIFEST
178178
/python
179179
!/Python/
180180

181-
# People's custom https://docs.anthropic.com/en/docs/claude-code/memory configs.
182-
/.claude/
181+
# Local AI agent scratch state (per-PR and per-branch notebooks, sandbox
182+
# experiments) and personal agent overrides, none of which are committed.
183+
/.claude/pr-*
184+
/.claude/branch-*
185+
/.claude/sandbox/
186+
AGENTS.local.md
183187
CLAUDE.local.md
184188

185189
#### main branch only stuff below this line, things to backport go above. ####

AGENTS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# AI agent guidance
2+
3+
CPython has a [policy on the use of AI tools](https://devguide.python.org/getting-started/ai-tools/).
4+
All use of AI tools and agents when working on or interacting with CPython
5+
must follow it.
6+
7+
> [!important]
8+
> **Primary directive**: Read the policy before making or proposing any changes.
9+
10+
When acting on this repository, apply the policy's core principles:
11+
12+
- Consider whether the change is necessary.
13+
- Make minimal, focused changes.
14+
- Follow existing coding style and patterns.
15+
- Write tests that exercise the change.
16+
- Keep backwards compatibility with prior releases in mind.

Doc/howto/curses.rst

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,21 @@ underline, reverse code, or in color. They'll be explained in more detail in
295295
the next subsection.
296296

297297

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

304306
The :meth:`~curses.window.addch` methods take a character, which can be
305-
either a string of length 1, a bytestring of length 1, or an integer.
307+
either a string of length 1, a bytestring of length 1, an integer, or a
308+
:class:`~curses.complexchar`.
306309

307-
Constants are provided for extension characters; these constants are
308-
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 +/-
309313
symbol, and :const:`ACS_ULCORNER` is the upper left corner of a box
310314
(handy for drawing borders). You can also use the appropriate Unicode
311315
character.
@@ -319,11 +323,11 @@ won't be distracting; it can be confusing to have the cursor blinking at some
319323
apparently random location.
320324

321325
If your application doesn't need a blinking cursor at all, you can
322-
call ``curs_set(False)`` to make it invisible. For compatibility
323-
with older curses versions, there's a ``leaveok(bool)`` function
324-
that's a synonym for :func:`~curses.curs_set`. When *bool* is true, the
325-
curses library will attempt to suppress the flashing cursor, and you
326-
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.
327331

328332

329333
Attributes and Color
@@ -364,6 +368,14 @@ could code::
364368
curses.A_REVERSE)
365369
stdscr.refresh()
366370

371+
A :class:`~curses.complexchar` carries its attributes and color pair
372+
together with the text of one character cell,
373+
and a :class:`~curses.complexstr` is a run of such cells.
374+
They are what :meth:`~curses.window.in_wch` and
375+
:meth:`~curses.window.in_wchstr` return,
376+
so a part of the screen can be read and written back
377+
with its appearance intact.
378+
367379
The curses library also supports color on those terminals that provide it. The
368380
most common such terminal is probably the Linux console, followed by color
369381
xterms.
@@ -429,40 +441,48 @@ The C curses library offers only very simple input mechanisms. Python's
429441
:mod:`curses` module adds a basic text-input widget. (Other libraries
430442
such as :pypi:`Urwid` have more extensive collections of widgets.)
431443

432-
There are two methods for getting input from a window:
444+
There are three methods for getting input from a window:
433445

434-
* :meth:`~curses.window.getch` refreshes the screen and then waits for
446+
* :meth:`~curses.window.get_wch` refreshes the screen and then waits for
435447
the user to hit a key, displaying the key if :func:`~curses.echo` has been
436448
called earlier. You can optionally specify a coordinate to which
437449
the cursor should be moved before pausing.
438450

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

444462
It's possible to not wait for the user using the
445463
:meth:`~curses.window.nodelay` window method. After ``nodelay(True)``,
446-
:meth:`!getch` and :meth:`!getkey` for the window become
447-
non-blocking. To signal that no input is ready, :meth:`!getch` returns
448-
``curses.ERR`` (a value of -1) and :meth:`!getkey` raises an exception.
464+
the reads for the window become non-blocking.
465+
To signal that no input is ready,
466+
:meth:`!get_wch` and :meth:`!getkey` raise an exception,
467+
and :meth:`!getch` returns ``-1``.
449468
There's also a :func:`~curses.halfdelay` function, which can be used to (in
450-
effect) set a timer on each :meth:`!getch`; if no input becomes
469+
effect) set a timer on each read; if no input becomes
451470
available within a specified delay (measured in tenths of a second),
452-
curses raises an exception.
471+
the read fails the same way.
453472

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

461481
while True:
462-
c = stdscr.getch()
463-
if c == ord('p'):
482+
c = stdscr.get_wch()
483+
if c == 'p':
464484
PrintDocument()
465-
elif c == ord('q'):
485+
elif c == 'q':
466486
break # Exit the while loop
467487
elif c == curses.KEY_HOME:
468488
x = y = 0
@@ -474,16 +494,17 @@ conversion functions that take either integer or 1-character-string arguments
474494
and return the same type. For example, :func:`curses.ascii.ctrl` returns the
475495
control character corresponding to its argument.
476496

477-
There's also a method to retrieve an entire string,
478-
:meth:`~curses.window.getstr`. It isn't used very often, because its
497+
There's also a method to retrieve an entire line,
498+
:meth:`~curses.window.get_wstr`. It isn't used very often, because its
479499
functionality is quite limited; the only editing keys available are
480-
the backspace key and the Enter key, which terminates the string. It
481-
can optionally be limited to a fixed number of characters. ::
500+
the erase and kill characters, and the Enter key, which terminates the line.
501+
It can optionally be limited to a fixed number of characters;
502+
:meth:`~curses.window.getstr` returns a bytes object instead. ::
482503

483504
curses.echo() # Enable echoing of characters
484505

485-
# Get a 15-character string, with the cursor on the top line
486-
s = stdscr.getstr(0,0, 15)
506+
# Get a line of at most 15 characters, with the cursor on the top line
507+
s = stdscr.get_wstr(0,0, 15)
487508

488509
The :mod:`curses.textpad` module supplies a text box that supports an
489510
Emacs-like set of keybindings. Various methods of the

Doc/library/atexit.rst

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,69 @@
66

77
--------------
88

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

2038
**Note:** The effect of registering or unregistering functions from within
2139
a cleanup function is undefined.
2240

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

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

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

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

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

4566
This function returns *func*, which makes it possible to use it as a
4667
decorator.
4768

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

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

Doc/library/curses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,8 @@ Other
20022002

20032003
.. attribute:: window.encoding
20042004

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

Doc/library/inspect.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
485485
Functions wrapped in :func:`functools.partial` now return ``True`` if the
486486
wrapped function is a Python generator function.
487487

488+
.. versionchanged:: 3.10.6
489+
:term:`Duck-typed <duck-typing>` function-like objects now return
490+
``True`` if their code object has the :data:`CO_GENERATOR` flag.
491+
488492
.. versionchanged:: 3.13
489493
Functions wrapped in :func:`functools.partialmethod` now return ``True``
490494
if the wrapped function is a Python generator function.
@@ -507,6 +511,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
507511
Functions wrapped in :func:`functools.partial` now return ``True`` if the
508512
wrapped function is a :term:`coroutine function`.
509513

514+
.. versionchanged:: 3.10.6
515+
:term:`Duck-typed <duck-typing>` function-like objects now return
516+
``True`` if their code object has the :data:`CO_COROUTINE` flag.
517+
510518
.. versionchanged:: 3.12
511519
Sync functions marked with :func:`markcoroutinefunction` now return
512520
``True``.
@@ -581,6 +589,10 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
581589
Functions wrapped in :func:`functools.partial` now return ``True`` if the
582590
wrapped function is an :term:`asynchronous generator` function.
583591

592+
.. versionchanged:: 3.10.6
593+
:term:`Duck-typed <duck-typing>` function-like objects now return
594+
``True`` if their code object has the :data:`CO_ASYNC_GENERATOR` flag.
595+
584596
.. versionchanged:: 3.13
585597
Functions wrapped in :func:`functools.partialmethod` now return ``True``
586598
if the wrapped function is a :term:`asynchronous generator` function.

Doc/library/urllib.request.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,10 @@ AbstractBasicAuthHandler Objects
10561056
authenticate for, *req* should be the (failed) :class:`Request` object, and
10571057
*headers* should be the error headers.
10581058

1059+
*headers* must be a mapping-like object with case-insensitive lookup
1060+
that implements the ``get_all()`` method,
1061+
such as :class:`email.message.Message` or :class:`wsgiref.headers.Headers`.
1062+
10591063
*host* is either an authority (e.g. ``"python.org"``) or a URL containing an
10601064
authority component (e.g. ``"https://python.org/"``). In either case, the
10611065
authority must not contain a userinfo component (so, ``"python.org"`` and
@@ -1097,6 +1101,9 @@ AbstractDigestAuthHandler Objects
10971101
should be the (failed) :class:`Request` object, and *headers* should be the
10981102
error headers.
10991103

1104+
*headers* must be a mapping-like object with case-insensitive lookup,
1105+
such as :class:`email.message.Message` or :class:`wsgiref.headers.Headers`.
1106+
11001107

11011108
.. _http-digest-auth-handler:
11021109

Doc/library/weakref.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ same issues as the :meth:`WeakKeyDictionary.keyrefs` method.
290290
from an object's :meth:`~object.__del__` method or a weak reference's
291291
callback.
292292

293-
When the program exits, each remaining live finalizer is called
294-
unless its :attr:`atexit` attribute has been set to false. They
295-
are called in reverse order of creation.
293+
When the program exits (or more generally, at :term:`interpreter shutdown`),
294+
each remaining live finalizer is called unless its :attr:`atexit` attribute
295+
has been set to false.
296+
They are called in reverse order of creation.
296297

297298
A finalizer will never invoke its callback during the later part of
298299
the :term:`interpreter shutdown` when module globals are liable to have
@@ -321,9 +322,9 @@ same issues as the :meth:`WeakKeyDictionary.keyrefs` method.
321322

322323
.. attribute:: atexit
323324

324-
A writable boolean property which by default is true. When the
325-
program exits, it calls all remaining live finalizers for which
326-
:attr:`.atexit` is true. They are called in reverse order of
325+
A writable boolean property which by default is true. At
326+
:term:`interpreter shutdown`, all remaining live finalizers for which
327+
:attr:`.atexit` is true are called in reverse order of
327328
creation.
328329

329330
.. note::

Doc/library/xml.etree.elementtree.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ for parsing and creating XML data.
1515
This module will use a fast implementation whenever available.
1616

1717
.. deprecated:: 3.3
18-
The :mod:`!xml.etree.cElementTree` module is deprecated.
18+
The :mod:`!xml.etree.cElementTree` alias of this module is deprecated.
1919

2020

2121
.. note::

0 commit comments

Comments
 (0)