8000 Merge branch 'main' into cibuildwheel · python/cpython@e4192b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4192b4

Browse files
authored
Merge branch 'main' into cibuildwheel
2 parents ddfb875 + dba9de7 commit e4192b4

File tree

158 files changed

+5054
-2508
lines changed

Some content is hidden

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

158 files changed

+5054
-2508
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,10 @@ Python/frozen_modules/MANIFEST
171171
/python
172172
!/Python/
173173

174+
# People's custom https://docs.anthropic.com/en/docs/claude-code/memory configs.
175+
/.claude/
176+
CLAUDE.local.md
177+
178+
#### main branch only stuff below this line, things to backport go above. ####
174179
# main branch only: ABI files are not checked/maintained.
175180
Doc/data/python*.abi

Doc/c-api/lifecycle.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ that must be true for *B* to occur after *A*.
5555
.. image:: lifecycle.dot.svg
5656
:align: center
5757
:class: invert-in-dark-mode
58-
:alt: Diagram showing events in an object's life. Explained in detail
59-
below.
58+
:alt: Diagram showing events in an object's life. Explained in detail below.
6059
6160
.. only:: latex
6261
6362
.. image:: lifecycle.dot.pdf
6463
:align: center
6564
:class: invert-in-dark-mode
66-
:alt: Diagram showing events in an object's life. Explained in detail
67-
below.
65+
:alt: Diagram showing events in an object's life. Explained in detail below.
6866
6967
.. container::
7068
:name: life-events-graph-description

Doc/c-api/module.rst

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,40 @@ An alternate way to specify extensions is to request "multi-phase initialization
288288
Extension modules created this way behave more like Python modules: the
289289
initialization is split between the *creation phase*, when the module object
290290
is created, and the *execution phase*, when it is populated.
291-
The distinction is similar to the :py:meth:`!__new__` and :py:meth:`!__init__` methods
292-
of classes.
291+
The distinction is similar to the :py:meth:`~object.__new__` and
292+
:py:meth:`~object.__init__` methods of classes.
293293
294294
Unlike modules created using single-phase initialization, these modules are not
295-
singletons: if the *sys.modules* entry is removed and the module is re-imported,
296-
a new module object is created, and the old module is subject to normal garbage
297-
collection -- as with Python modules.
298-
By default, multiple modules created from the same definition should be
299-
independent: changes to one should not affect the others.
300-
This means that all state should be specific to the module object (using e.g.
301-
using :c:func:`PyModule_GetState`), or its contents (such as the module's
302-
:attr:`~object.__dict__` or individual classes created with :c:func:`PyType_FromSpec`).
295+
singletons.
296+
For example, if the :py:attr:`sys.modules` entry is removed and the module
297+
is re-imported, a new module object is created, and typically populated with
298+
fresh method and type objects.
299+
The old module is subject to normal garbage collection.
300+
This mirrors the behavior of pure-Python modules.
301+
302+
Additional module instances may be created in
303+
:ref:`sub-interpreters <sub-interpreter-support>`
304+
or after after Python runtime reinitialization
305+
(:c:func:`Py_Finalize` and :c:func:`Py_Initialize`).
306+
In these cases, sharing Python objects between module instances would likely
307+
cause crashes or undefined behavior.
308+
309+
To avoid such issues, each instance of an extension module should
310+
be *isolated*: changes to one instance should not implicitly affect the others,
311+
and all state, including references to Python objects, should be specific to
312+
a particular module instance.
313+
See :ref:`isolating-extensions-howto` for more details and a practical guide.
314+
315+
A simpler way to avoid these issues is
316+
:ref:`raising an error on repeated initialization <isolating-extensions-optout>`.
303317
304318
All modules created using multi-phase initialization are expected to support
305-
:ref:`sub-interpreters <sub-interpreter-support>`. Making sure multiple modules
306-
are independent is typically enough to achieve this.
319+
:ref:`sub-interpreters <sub-interpreter-support>`, or otherwise explicitly
320+
signal a lack of support.
321+
This is usually achieved by isolation or blocking repeated initialization,
322+
as above.
323+
A module may also be limited to the main interpreter using
324+
the :c:data:`Py_mod_multiple_interpreters` slot.
307325
308326
To request multi-phase initialization, the initialization function
309327
(PyInit_modulename) returns a :c:type:`PyModuleDef` instance with non-empty

Doc/c-api/stable.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ It is generally intended for specialized, low-level tools like debuggers.
5151
Projects that use this API are expected to follow
5252
CPython development and spend extra effort adjusting to changes.
5353

54+
.. _stable-application-binary-interface:
5455

5556
Stable Application Binary Interface
5657
===================================

Doc/c-api/unicode.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,10 +1461,6 @@ the user settings on the machine running the codec.
14611461
.. versionadded:: 3.3
14621462
14631463
1464-
Methods & Slots
1465-
"""""""""""""""
1466-
1467-
14681464
.. _unicodemethodsandslots:
14691465
14701466
Methods and Slot Functions

Doc/deprecations/pending-removal-in-3.19.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ Pending removal in Python 3.19
66
* Implicitly switching to the MSVC-compatible struct layout by setting
77
:attr:`~ctypes.Structure._pack_` but not :attr:`~ctypes.Structure._layout_`
88
on non-Windows platforms.
9+
10+
* :mod:`hashlib`:
11+
12+
- In hash function constructors such as :func:`~hashlib.new` or the
13+
direct hash-named constructors such as :func:`~hashlib.md5` and
14+
:func:`~hashlib.sha256`, their optional initial data parameter could
15+
also be passed a keyword argument named ``data=`` or ``string=`` in
16+
various :mod:`!hashlib` implementations.
17+
18+
Support for the ``string`` keyword argument name is now deprecated
19+
and slated for removal in Python 3.19.
20+
21+
Before Python 3.13, the ``string`` keyword parameter was not correctly
22+
supported depending on the backend implementation of hash functions.
23+
Prefer passing the initial data as a positional argument for maximum
24+
backwards compatibility.

Doc/extending/windows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ When creating DLLs in Windows, you can use the CPython library in two ways:
121121
:file:`Python.h` triggers an implicit, configure-aware link with the
122122
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
123123
:file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with
124-
the `Limited API <stable-application-binary-interface>`_ enabled.
124+
the :ref:`Limited API <stable-application-binary-interface>` enabled.
125125

126126
To build two DLLs, spam and ni (which uses C functions found in spam), you
127127
could use these commands::

Doc/howto/isolating-extensions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ possible, consider explicit locking.
168168
If it is necessary to use process-global state, the simplest way to
169169
avoid issues with multiple interpreters is to explicitly prevent a
170170
module from being loaded more than once per process—see
171-
`Opt-Out: Limiting to One Module Object per Process`_.
171+
:ref:`isolating-extensions-optout`.
172172

173173

174174
Managing Per-Module State
@@ -207,6 +207,8 @@ An example of a module with per-module state is currently available as
207207
example module initialization shown at the bottom of the file.
208208

209209

210+
.. _isolating-extensions-optout:
211+
210212
Opt-Out: Limiting to One Module Object per Process
211213
--------------------------------------------------
212214

Doc/howto/urllib2.rst

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -245,75 +245,27 @@ codes in the 100--299 range indicate success, you will usually only see error
245245
codes in the 400--599 range.
246246

247247
:attr:`http.server.BaseHTTPRequestHandler.responses` is a useful dictionary of
248-
response codes in that shows all the response codes used by :rfc:`2616`. The
249-
dictionary is reproduced here for convenience ::
248+
response codes that shows all the response codes used by :rfc:`2616`.
249+
An excerpt from the dictionary is shown below ::
250250

251-
# Table mapping response codes to messages; entries have the
252-
# form {code: (shortmessage, longmessage)}.
253251
responses = {
254-
100: ('Continue', 'Request received, please continue'),
255-
101: ('Switching Protocols',
256-
'Switching to new protocol; obey Upgrade header'),
257-
258-
200: ('OK', 'Request fulfilled, document follows'),
259-
201: ('Created', 'Document created, URL follows'),
260-
202: ('Accepted',
261-
'Request accepted, processing continues off-line'),
262-
203: ('Non-Authoritative Information', 'Request fulfilled from cache'),
263-
204: ('No Content', 'Request fulfilled, nothing follows'),
264-
205: ('Reset Content', 'Clear input form for further input.'),
265-
206: ('Partial Content', 'Partial content follows.'),
266-
267-
300: ('Multiple Choices',
268-
'Object has several resources -- see URI list'),
269-
301: ('Moved Permanently', 'Object moved permanently -- see URI list'),
270-
302: ('Found', 'Object moved temporarily -- see URI list'),
271-
303: ('See Other', 'Object moved -- see Method and URL list'),
272-
304: ('Not Modified',
273-
'Document has not changed since given time'),
274-
305: ('Use Proxy',
275-
'You must use proxy specified in Location to access this '
276-
'resource.'),
277-
307: ('Temporary Redirect',
278-
'Object moved temporarily -- see URI list'),
279-
280-
400: ('Bad Request',
281-
'Bad request syntax or unsupported method'),
282-
401: ('Unauthorized',
283-
'No permission -- see authorization schemes'),
284-
402: ('Payment Required',
285-
'No payment -- see charging schemes'),
286-
403: ('Forbidden',
287-
'Request forbidden -- authorization will not help'),
288-
404: ('Not Found', 'Nothing matches the given URI'),
289-
405: ('Method Not Allowed',
290-
'Specified method is invalid for this server.'),
291-
406: ('Not Acceptable', 'URI not available in preferred format.'),
292-
407: ('Proxy Authentication Required', 'You must authenticate with '
293-
'this proxy before proceeding.'),
294-
408: ('Request Timeout', 'Request timed out; try again later.'),
295-
409: ('Conflict', 'Request conflict.'),
296-
410: ('Gone',
297-
'URI no longer exists and has been permanently removed.'),
298-
411: ('Length Required', 'Client must specify Content-Length.'),
299-
412: ('Precondition Failed', 'Precondition in headers is false.'),
300-
413: ('Request Entity Too Large', 'Entity is too large.'),
301-
414: ('Request-URI Too Long', 'URI is too long.'),
302-
415: ('Unsupported Media Type', 'Entity body in unsupported format.'),
303-
416: ('Requested Range Not Satisfiable',
304-
'Cannot satisfy request range.'),
305-
417: ('Expectation Failed',
306-
'Expect condition could not be satisfied.'),
307-
308-
500: ('Internal Server Error', 'Server got itself in trouble'),
309-
501: ('Not Implemented',
310-
'Server does not support this operation'),
311-
502: ('Bad Gateway', 'Invalid responses from another server/proxy.'),
312-
503: ('Service Unavailable',
313-
'The server cannot process the request due to a high load'),
314-
504: ('Gateway Timeout',
315-
'The gateway server did not receive a timely response'),
316-
505: ('HTTP Version Not Supported', 'Cannot fulfill request.'),
252+
...
253+
<HTTPStatus.OK: 200>: ('OK', 'Request fulfilled, document follows'),
254+
...
255+
<HTTPStatus.FORBIDDEN: 403>: ('Forbidden',
256+
'Request forbidden -- authorization will '
257+
'not help'),
258+
<HTTPStatus.NOT_FOUND: 404>: ('Not Found',
259+
'Nothing matches the given URI'),
260+
...
261+
<HTTPStatus.IM_A_TEAPOT: 418>: ("I'm a Teapot",
262+
'Server refuses to brew coffee because '
263+
'it is a teapot'),
264+
...
265+
<HTTPStatus.SERVICE_UNAVAILABLE: 503>: ('Service Unavailable',
266+
'The server cannot process the '
267+
'request due to a high load'),
268+
...
317269
}
318270

319271
When an error is raised the server responds by returning an HTTP error code

Doc/library/argparse.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,12 +2122,15 @@ Partial parsing
21222122

21232123
.. method:: ArgumentParser.parse_known_args(args=None, namespace=None)
21242124

2125-
Sometimes a script may only parse a few of the command-line arguments, passing
2126-
the remaining arguments on to another script or program. In these cases, the
2127-
:meth:`~ArgumentParser.parse_known_args` method can be useful. It works much like
2128-
:meth:`~ArgumentParser.parse_args` except that it does not produce an error when
2129-
extra arguments are present. Instead, it returns a two item tuple containing
2130-
the populated namespace and the list of remaining argument strings.
2125+
Sometimes a script only needs to handle a specific set of command-line
2126+
arguments, leaving any unrecognized arguments for another script or program.
2127+
In these cases, the :meth:`~ArgumentParser.parse_known_args` method can be
2128+
useful.
2129+
2130+
This method works similarly to :meth:`~ArgumentParser.parse_args`, but it does
2131+
not raise an error for extra, unrecognized arguments. Instead, it parses the
2132+
known arguments and returns a two item tuple that contains the populated
2133+
namespace and the list of any unrecognized arguments.
21312134

21322135
::
21332136

0 commit comments

Comments
 (0)
0