Skip to content

Commit e5827e7

Browse files
Sync with main
2 parents 98d1566 + 1e9dfda commit e5827e7

File tree

196 files changed

+3358
-1639
lines changed

Some content is hidden

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

196 files changed

+3358
-1639
lines changed

Doc/extending/newtypes_tutorial.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ standard Python floats::
8888
The second bit is the definition of the type object. ::
8989

9090
static PyTypeObject CustomType = {
91-
PyVarObject_HEAD_INIT(NULL, 0)
91+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
9292
.tp_name = "custom.Custom",
9393
.tp_doc = PyDoc_STR("Custom objects"),
9494
.tp_basicsize = sizeof(CustomObject),
@@ -109,7 +109,7 @@ common practice to not specify them explicitly unless you need them.
109109

110110
We're going to pick it apart, one field at a time::
111111

112-
PyVarObject_HEAD_INIT(NULL, 0)
112+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
113113

114114
This line is mandatory boilerplate to initialize the ``ob_base``
115115
field mentioned above. ::

Doc/howto/enum.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -988,12 +988,11 @@ but remain normal attributes.
988988
""""""""""""""""""""
989989

990990
Enum members are instances of their enum class, and are normally accessed as
991-
``EnumClass.member``. In Python versions starting with ``3.5`` you could access
992-
members from other members -- this practice is discouraged, is deprecated
993-
in ``3.12``, and will be removed in ``3.14``.
991+
``EnumClass.member``. In certain situations, such as writing custom enum
992+
behavior, being able to access one member directly from another is useful,
993+
and is supported.
994994

995995
.. versionchanged:: 3.5
996-
.. versionchanged:: 3.12
997996

998997

999998
Creating members that are mixed with other data types

Doc/includes/custom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ typedef struct {
77
} CustomObject;
88

99
static PyTypeObject CustomType = {
10-
PyVarObject_HEAD_INIT(NULL, 0)
10+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
1111
.tp_name = "custom.Custom",
1212
.tp_doc = PyDoc_STR("Custom objects"),
1313
.tp_basicsize = sizeof(CustomObject),
@@ -17,7 +17,7 @@ static PyTypeObject CustomType = {
1717
};
1818

1919
static PyModuleDef custommodule = {
20-
PyModuleDef_HEAD_INIT,
20+
.m_base = PyModuleDef_HEAD_INIT,
2121
.m_name = "custom",
2222
.m_doc = "Example module that creates an extension type.",
2323
.m_size = -1,

Doc/includes/custom2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static PyMethodDef Custom_methods[] = {
9090
};
9191

9292
static PyTypeObject CustomType = {
93-
PyVarObject_HEAD_INIT(NULL, 0)
93+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
9494
.tp_name = "custom2.Custom",
9595
.tp_doc = PyDoc_STR("Custom objects"),
9696
.tp_basicsize = sizeof(CustomObject),
@@ -104,7 +104,7 @@ static PyTypeObject CustomType = {
104104
};
105105

106106
static PyModuleDef custommodule = {
107-
PyModuleDef_HEAD_INIT,
107+
.m_base =PyModuleDef_HEAD_INIT,
108108
.m_name = "custom2",
109109
.m_doc = "Example module that creates an extension type.",
110110
.m_size = -1,

Doc/includes/custom3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static PyMethodDef Custom_methods[] = {
130130
};
131131

132132
static PyTypeObject CustomType = {
133-
PyVarObject_HEAD_INIT(NULL, 0)
133+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
134134
.tp_name = "custom3.Custom",
135135
.tp_doc = PyDoc_STR("Custom objects"),
136136
.tp_basicsize = sizeof(CustomObject),
@@ -145,7 +145,7 @@ static PyTypeObject CustomType = {
145145
};
146146

147147
static PyModuleDef custommodule = {
148-
PyModuleDef_HEAD_INIT,
148+
.m_base = PyModuleDef_HEAD_INIT,
149149
.m_name = "custom3",
150150
.m_doc = "Example module that creates an extension type.",
151151
.m_size = -1,

Doc/includes/custom4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static PyMethodDef Custom_methods[] = {
146146
};
147147

148148
static PyTypeObject CustomType = {
149-
PyVarObject_HEAD_INIT(NULL, 0)
149+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
150150
.tp_name = "custom4.Custom",
151151
.tp_doc = PyDoc_STR("Custom objects"),
152152
.tp_basicsize = sizeof(CustomObject),
@@ -163,7 +163,7 @@ static PyTypeObject CustomType = {
163163
};
164164

165165
static PyModuleDef custommodule = {
166-
PyModuleDef_HEAD_INIT,
166+
.m_base = PyModuleDef_HEAD_INIT,
167167
.m_name = "custom4",
168168
.m_doc = "Example module that creates an extension type.",
169169
.m_size = -1,

Doc/library/bisect.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ records in a table::
210210
>>> Movie = namedtuple('Movie', ('name', 'released', 'director'))
211211

212212
>>> movies = [
213-
... Movie('Jaws', 1975, 'Speilberg'),
213+
... Movie('Jaws', 1975, 'Spielberg'),
214214
... Movie('Titanic', 1997, 'Cameron'),
215215
... Movie('The Birds', 1963, 'Hitchcock'),
216-
... Movie('Aliens', 1986, 'Scott')
216+
... Movie('Aliens', 1986, 'Cameron')
217217
... ]
218218

219219
>>> # Find the first movie released after 1960
@@ -228,8 +228,8 @@ records in a table::
228228
>>> pprint(movies)
229229
[Movie(name='The Birds', released=1963, director='Hitchcock'),
230230
Movie(name='Love Story', released=1970, director='Hiller'),
231-
Movie(name='Jaws', released=1975, director='Speilberg'),
232-
Movie(name='Aliens', released=1986, director='Scott'),
231+
Movie(name='Jaws', released=1975, director='Spielberg'),
232+
Movie(name='Aliens', released=1986, director='Cameron'),
233233
Movie(name='Titanic', released=1997, director='Cameron')]
234234

235235
If the key function is expensive, it is possible to avoid repeated function

Doc/library/dis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ the following command can be used to display the disassembly of
5959
3 2 LOAD_GLOBAL 1 (NULL + len)
6060
12 LOAD_FAST 0 (alist)
6161
14 CALL 1
62-
24 RETURN_VALUE
62+
22 RETURN_VALUE
6363

6464
(The "2" is a line number).
6565

Doc/library/functions.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,9 @@ are always available. They are listed here in alphabetical order.
14441444
arguments are converted to text strings, :func:`print` cannot be used with
14451445
binary mode file objects. For these, use ``file.write(...)`` instead.
14461446

1447-
Whether the output is buffered is usually determined by *file*, but if the
1448-
*flush* keyword argument is true, the stream is forcibly flushed.
1447+
Output buffering is usually determined by *file*.
1448+
However, if *flush* is true, the stream is forcibly flushed.
1449+
14491450

14501451
.. versionchanged:: 3.3
14511452
Added the *flush* keyword argument.

Doc/library/http.client.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ HTTPConnection Objects
353353
The *headers* argument should be a mapping of extra HTTP headers to send with
354354
the CONNECT request.
355355

356+
As HTTP/1.1 is used for HTTP CONNECT tunnelling request, `as per the RFC
357+
<https://tools.ietf.org/html/rfc7231#section-4.3.6>`_, a HTTP ``Host:``
358+
header must be provided, matching the authority-form of the request target
359+
provided as the destination for the CONNECT request. If a HTTP ``Host:``
360+
header is not provided via the headers argument, one is generated and
361+
transmitted automatically.
362+
356363
For example, to tunnel through a HTTPS proxy server running locally on port
357364
8080, we would pass the address of the proxy to the :class:`HTTPSConnection`
358365
constructor, and the address of the host that we eventually want to reach to
@@ -365,6 +372,11 @@ HTTPConnection Objects
365372

366373
.. versionadded:: 3.2
367374

375+
.. versionchanged:: 3.12
376+
HTTP CONNECT tunnelling requests use protocol HTTP/1.1, upgraded from
377+
protocol HTTP/1.0. ``Host:`` HTTP headers are mandatory for HTTP/1.1, so
378+
one will be automatically generated and transmitted if not provided in
379+
the headers argument.
368380

369381
.. method:: HTTPConnection.connect()
370382

Doc/library/multiprocessing.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,16 @@ process which created it.
460460
... return x*x
461461
...
462462
>>> with p:
463-
... p.map(f, [1,2,3])
463+
... p.map(f, [1,2,3])
464464
Process PoolWorker-1:
465465
Process PoolWorker-2:
466466
Process PoolWorker-3:
467467
Traceback (most recent call last):
468468
Traceback (most recent call last):
469469
Traceback (most recent call last):
470-
AttributeError: 'module' object has no attribute 'f'
471-
AttributeError: 'module' object has no attribute 'f'
472-
AttributeError: 'module' object has no attribute 'f'
470+
AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
471+
AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
472+
AttributeError: Can't get attribute 'f' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
473473

474474
(If you try this it will actually output three full tracebacks
475475
interleaved in a semi-random fashion, and then you may have to

Doc/library/shutil.rst

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,43 @@ Directory and files operations
433433
When no *path* is specified, the results of :func:`os.environ` are used,
434434
returning either the "PATH" value or a fallback of :attr:`os.defpath`.
435435

436-
On Windows, the current directory is always prepended to the *path* whether
437-
or not you use the default or provide your own, which is the behavior the
438-
command shell uses when finding executables. Additionally, when finding the
439-
*cmd* in the *path*, the ``PATHEXT`` environment variable is checked. For
440-
example, if you call ``shutil.which("python")``, :func:`which` will search
441-
``PATHEXT`` to know that it should look for ``python.exe`` within the *path*
442-
directories. For example, on Windows::
436+
On Windows, the current directory is prepended to the *path* if *mode* does
437+
not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the
438+
Windows API ``NeedCurrentDirectoryForExePathW`` will be consulted to
439+
determine if the current directory should be prepended to *path*. To avoid
440+
consulting the current working directory for executables: set the environment
441+
variable ``NoDefaultCurrentDirectoryInExePath``.
442+
443+
Also on Windows, the ``PATHEXT`` variable is used to resolve commands
444+
that may not already include an extension. For example, if you call
445+
``shutil.which("python")``, :func:`which` will search ``PATHEXT``
446+
to know that it should look for ``python.exe`` within the *path*
447+
directories. For example, on Windows::
443448

444449
>>> shutil.which("python")
445450
'C:\\Python33\\python.EXE'
446451

452+
This is also applied when *cmd* is a path that contains a directory
453+
component::
454+
455+
>> shutil.which("C:\\Python33\\python")
456+
'C:\\Python33\\python.EXE'
457+
447458
.. versionadded:: 3.3
448459

449460
.. versionchanged:: 3.8
450461
The :class:`bytes` type is now accepted. If *cmd* type is
451462
:class:`bytes`, the result type is also :class:`bytes`.
452463

464+
.. versionchanged:: 3.12
465+
On Windows, the current directory is no longer prepended to the search
466+
path if *mode* includes ``os.X_OK`` and WinAPI
467+
``NeedCurrentDirectoryForExePathW(cmd)`` is false, else the current
468+
directory is prepended even if it is already in the search path;
469+
``PATHEXT`` is used now even when *cmd* includes a directory component
470+
or ends with an extension that is in ``PATHEXT``; and filenames that
471+
have no extension can now be found.
472+
453473
.. exception:: Error
454474

455475
This exception collects exceptions that are raised during a multi-file

Doc/library/socket.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ to sockets.
17751775
much data, if any, was successfully sent.
17761776

17771777
.. versionchanged:: 3.5
1778-
The socket timeout is no more reset each time data is sent successfully.
1778+
The socket timeout is no longer reset each time data is sent successfully.
17791779
The socket timeout is now the maximum total duration to send all data.
17801780

17811781
.. versionchanged:: 3.5
@@ -1998,8 +1998,8 @@ can be changed by calling :func:`setdefaulttimeout`.
19981998

19991999
* In *non-blocking mode*, operations fail (with an error that is unfortunately
20002000
system-dependent) if they cannot be completed immediately: functions from the
2001-
:mod:`select` can be used to know when and whether a socket is available for
2002-
reading or writing.
2001+
:mod:`select` module can be used to know when and whether a socket is available
2002+
for reading or writing.
20032003

20042004
* In *timeout mode*, operations fail if they cannot be completed within the
20052005
timeout specified for the socket (they raise a :exc:`timeout` exception)
@@ -2188,7 +2188,7 @@ manager protocol instead, open a socket with::
21882188
socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM)
21892189

21902190
After binding (:const:`CAN_RAW`) or connecting (:const:`CAN_BCM`) the socket, you
2191-
can use the :meth:`socket.send`, and the :meth:`socket.recv` operations (and
2191+
can use the :meth:`socket.send` and :meth:`socket.recv` operations (and
21922192
their counterparts) on the socket object as usual.
21932193

21942194
This last example might require special privileges::

Doc/library/sys.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ always available.
697697
the encoding used with the :term:`filesystem error handler <filesystem
698698
encoding and error handler>` to convert between Unicode filenames and bytes
699699
filenames. The filesystem error handler is returned from
700-
:func:`getfilesystemencoding`.
700+
:func:`getfilesystemencodeerrors`.
701701

702702
For best compatibility, str should be used for filenames in all cases,
703703
although representing filenames as bytes is also supported. Functions

Doc/library/typing.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,15 +1598,6 @@ These are not used in annotations. They are building blocks for creating generic
15981598
import threading
15991599
assert isinstance(threading.Thread(name='Bob'), Named)
16001600

1601-
.. versionchanged:: 3.12
1602-
The internal implementation of :func:`isinstance` checks against
1603-
runtime-checkable protocols now uses :func:`inspect.getattr_static`
1604-
to look up attributes (previously, :func:`hasattr` was used).
1605-
As a result, some objects which used to be considered instances
1606-
of a runtime-checkable protocol may no longer be considered instances
1607-
of that protocol on Python 3.12+, and vice versa.
1608-
Most users are unlikely to be affected by this change.
1609-
16101601
.. note::
16111602

16121603
:func:`!runtime_checkable` will check only the presence of the required
@@ -1628,6 +1619,24 @@ These are not used in annotations. They are building blocks for creating generic
16281619

16291620
.. versionadded:: 3.8
16301621

1622+
.. versionchanged:: 3.12
1623+
The internal implementation of :func:`isinstance` checks against
1624+
runtime-checkable protocols now uses :func:`inspect.getattr_static`
1625+
to look up attributes (previously, :func:`hasattr` was used).
1626+
As a result, some objects which used to be considered instances
1627+
of a runtime-checkable protocol may no longer be considered instances
1628+
of that protocol on Python 3.12+, and vice versa.
1629+
Most users are unlikely to be affected by this change.
1630+
1631+
.. versionchanged:: 3.12
1632+
The members of a runtime-checkable protocol are now considered "frozen"
1633+
at runtime as soon as the class has been created. Monkey-patching
1634+
attributes onto a runtime-checkable protocol will still work, but will
1635+
have no impact on :func:`isinstance` checks comparing objects to the
1636+
protocol. See :ref:`"What's new in Python 3.12" <whatsnew-typing-py312>`
1637+
for more details.
1638+
1639+
16311640
Other special directives
16321641
""""""""""""""""""""""""
16331642

Doc/tools/extensions/c_annotations.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
from os import path
23+
import docutils
2324
from docutils import nodes
2425
from docutils.parsers.rst import directives
2526
from docutils.parsers.rst import Directive
@@ -41,6 +42,16 @@
4142
}
4243

4344

45+
# Monkeypatch nodes.Node.findall for forwards compatability
46+
# This patch can be dropped when the minimum Sphinx version is 4.4.0
47+
# or the minimum Docutils version is 0.18.1.
48+
if docutils.__version_info__ < (0, 18, 1):
49+
def findall(self, *args, **kwargs):
50+
return iter(self.traverse(*args, **kwargs))
51+
52+
nodes.Node.findall = findall
53+
54+
4455
class RCEntry:
4556
def __init__(self, name):
4657
self.name = name
@@ -87,7 +98,7 @@ def __init__(self, refcount_filename, stable_abi_file):
8798
self.stable_abi_data[name] = record
8899

89100
def add_annotations(self, app, doctree):
90-
for node in doctree.traverse(addnodes.desc_content):
101+
for node in doctree.findall(addnodes.desc_content):
91102
par = node.parent
92103
if par['domain'] != 'c':
93104
continue

0 commit comments

Comments
 (0)