Skip to content

Commit c667049

Browse files
Merge branch 'main' into gh-130804-pyrepl-unicode-chars
2 parents bfa2e4e + 36ef3bf commit c667049

File tree

192 files changed

+5845
-3359
lines changed

Some content is hidden

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

192 files changed

+5845
-3359
lines changed

Doc/c-api/intro.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ familiar with writing an extension before attempting to embed Python in a real
3030
application.
3131

3232

33+
Language version compatibility
34+
==============================
35+
36+
Python's C API is compatible with C11 and C++11 versions of C and C++.
37+
38+
This is a lower limit: the C API does not require features from later
39+
C/C++ versions.
40+
You do *not* need to enable your compiler's "c11 mode".
41+
42+
3343
Coding standards
3444
================
3545

Doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
# Minimum version of sphinx required
102102
# Keep this version in sync with ``Doc/requirements.txt``.
103-
needs_sphinx = '8.1.3'
103+
needs_sphinx = '8.2.0'
104104

105105
# Create table of contents entries for domain objects (e.g. functions, classes,
106106
# attributes, etc.). Default is True.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ although there is currently no date scheduled for their removal.
127127

128128
* :class:`typing.Text` (:gh:`92332`).
129129

130+
* The internal class ``typing._UnionGenericAlias`` is no longer used to implement
131+
:class:`typing.Union`. To preserve compatibility with users using this private
132+
class, a compatibility shim will be provided until at least Python 3.17. (Contributed by
133+
Jelle Zijlstra in :gh:`105499`.)
134+
130135
* :class:`unittest.IsolatedAsyncioTestCase`: it is deprecated to return a value
131136
that is not ``None`` from a test case.
132137

Doc/extending/embedding.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ interesting part with respect to embedding Python starts with ::
196196

197197
After initializing the interpreter, the script is loaded using
198198
:c:func:`PyImport_Import`. This routine needs a Python string as its argument,
199-
which is constructed using the :c:func:`PyUnicode_FromString` data conversion
200-
routine. ::
199+
which is constructed using the :c:func:`PyUnicode_DecodeFSDefault` data
200+
conversion routine. ::
201201

202202
pFunc = PyObject_GetAttrString(pModule, argv[2]);
203203
/* pFunc is a new reference */

Doc/extending/windows.rst

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ gives you access to spam's names, but does not create a separate copy. On Unix,
9696
linking with a library is more like ``from spam import *``; it does create a
9797
separate copy.
9898

99+
.. c:macro:: Py_NO_LINK_LIB
100+
101+
Turn off the implicit, ``#pragma``-based linkage with the Python
102+
library, performed inside CPython header files.
103+
104+
.. versionadded:: 3.14
105+
99106

100107
.. _win-dlls:
101108

@@ -108,21 +115,46 @@ Using DLLs in Practice
108115
Windows Python is built in Microsoft Visual C++; using other compilers may or
109116
may not work. The rest of this section is MSVC++ specific.
110117

111-
When creating DLLs in Windows, you must pass :file:`pythonXY.lib` to the linker.
112-
To build two DLLs, spam and ni (which uses C functions found in spam), you could
113-
use these commands::
118+
When creating DLLs in Windows, you can use the CPython library in two ways:
119+
120+
1. By default, inclusion of :file:`PC/pyconfig.h` directly or via
121+
:file:`Python.h` triggers an implicit, configure-aware link with the
122+
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
123+
:file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with
124+
the `Limited API <stable-application-binary-interface>`_ enabled.
125+
126+
To build two DLLs, spam and ni (which uses C functions found in spam), you
127+
could use these commands::
128+
129+
cl /LD /I/python/include spam.c
130+
cl /LD /I/python/include ni.c spam.lib
131+
132+
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
133+
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
134+
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
135+
the Python code thanks to the implicitly linked :file:`pythonXY.lib`.
136+
137+
The second command created :file:`ni.dll` (and :file:`.obj` and
138+
:file:`.lib`), which knows how to find the necessary functions from spam,
139+
and also from the Python executable.
140+
141+
2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including
142+
:file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker.
143+
144+
To build two DLLs, spam and ni (which uses C functions found in spam), you
145+
could use these commands::
114146

115-
cl /LD /I/python/include spam.c ../libs/pythonXY.lib
116-
cl /LD /I/python/include ni.c spam.lib ../libs/pythonXY.lib
147+
cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib
148+
cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib
117149

118-
The first command created three files: :file:`spam.obj`, :file:`spam.dll` and
119-
:file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such
120-
as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code
121-
thanks to :file:`pythonXY.lib`.
150+
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
151+
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
152+
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
153+
the Python code thanks to :file:`pythonXY.lib`.
122154

123-
The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`),
124-
which knows how to find the necessary functions from spam, and also from the
125-
Python executable.
155+
The second command created :file:`ni.dll` (and :file:`.obj` and
156+
:file:`.lib`), which knows how to find the necessary functions from spam,
157+
and also from the Python executable.
126158

127159
Not every identifier is exported to the lookup table. If you want any other
128160
modules (including Python) to be able to see your identifiers, you have to say

Doc/library/asyncio-subprocess.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Creating Subprocesses
6868
Create a subprocess.
6969

7070
The *limit* argument sets the buffer limit for :class:`StreamReader`
71-
wrappers for :attr:`Process.stdout` and :attr:`Process.stderr`
71+
wrappers for :attr:`~asyncio.subprocess.Process.stdout` and :attr:`~asyncio.subprocess.Process.stderr`
7272
(if :const:`subprocess.PIPE` is passed to *stdout* and *stderr* arguments).
7373

7474
Return a :class:`~asyncio.subprocess.Process` instance.
@@ -87,7 +87,7 @@ Creating Subprocesses
8787
Run the *cmd* shell command.
8888

8989
The *limit* argument sets the buffer limit for :class:`StreamReader`
90-
wrappers for :attr:`Process.stdout` and :attr:`Process.stderr`
90+
wrappers for :attr:`~asyncio.subprocess.Process.stdout` and :attr:`~asyncio.subprocess.Process.stderr`
9191
(if :const:`subprocess.PIPE` is passed to *stdout* and *stderr* arguments).
9292

9393
Return a :class:`~asyncio.subprocess.Process` instance.
@@ -132,12 +132,12 @@ Constants
132132

133133
If *PIPE* is passed to *stdin* argument, the
134134
:attr:`Process.stdin <asyncio.subprocess.Process.stdin>` attribute
135-
will point to a :class:`StreamWriter` instance.
135+
will point to a :class:`~asyncio.StreamWriter` instance.
136136

137137
If *PIPE* is passed to *stdout* or *stderr* arguments, the
138138
:attr:`Process.stdout <asyncio.subprocess.Process.stdout>` and
139139
:attr:`Process.stderr <asyncio.subprocess.Process.stderr>`
140-
attributes will point to :class:`StreamReader` instances.
140+
attributes will point to :class:`~asyncio.StreamReader` instances.
141141

142142
.. data:: asyncio.subprocess.STDOUT
143143
:module:
@@ -165,7 +165,7 @@ their completion.
165165
:module:
166166

167167
An object that wraps OS processes created by the
168-
:func:`create_subprocess_exec` and :func:`create_subprocess_shell`
168+
:func:`~asyncio.create_subprocess_exec` and :func:`~asyncio.create_subprocess_shell`
169169
functions.
170170

171171
This class is designed to have a similar API to the
@@ -263,24 +263,24 @@ their completion.
263263

264264
Kill the child process.
265265

266-
On POSIX systems this method sends :py:data:`SIGKILL` to the child
266+
On POSIX systems this method sends :py:data:`~signal.SIGKILL` to the child
267267
process.
268268

269269
On Windows this method is an alias for :meth:`terminate`.
270270

271271
.. attribute:: stdin
272272

273-
Standard input stream (:class:`StreamWriter`) or ``None``
273+
Standard input stream (:class:`~asyncio.StreamWriter`) or ``None``
274274
if the process was created with ``stdin=None``.
275275

276276
.. attribute:: stdout
277277

278-
Standard output stream (:class:`StreamReader`) or ``None``
278+
Standard output stream (:class:`~asyncio.StreamReader`) or ``None``
279279
if the process was created with ``stdout=None``.
280280

281281
.. attribute:: stderr
282282

283-
Standard error stream (:class:`StreamReader`) or ``None``
283+
Standard error stream (:class:`~asyncio.StreamReader`) or ``None``
284284
if the process was created with ``stderr=None``.
285285

286286
.. warning::
@@ -296,7 +296,7 @@ their completion.
296296

297297
Process identification number (PID).
298298

299-
Note that for processes created by the :func:`create_subprocess_shell`
299+
Note that for processes created by the :func:`~asyncio.create_subprocess_shell`
300300
function, this attribute is the PID of the spawned shell.
301301

302302
.. attribute:: returncode

Doc/library/functions.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,10 @@ are always available. They are listed here in alphabetical order.
14051405
:func:`io.TextIOWrapper.reconfigure`. When no *buffering* argument is
14061406
given, the default buffering policy works as follows:
14071407

1408-
* Binary files are buffered in fixed-size chunks; the size of the buffer is
1409-
chosen using a heuristic trying to determine the underlying device's "block
1410-
size" and falling back on :const:`io.DEFAULT_BUFFER_SIZE`. On many systems,
1411-
the buffer will typically be 4096 or 8192 bytes long.
1408+
* Binary files are buffered in fixed-size chunks; the size of the buffer
1409+
is ``max(min(blocksize, 8 MiB), DEFAULT_BUFFER_SIZE)``
1410+
when the device block size is available.
1411+
On most systems, the buffer will typically be 128 kilobytes long.
14121412

14131413
* "Interactive" text files (files for which :meth:`~io.IOBase.isatty`
14141414
returns ``True``) use line buffering. Other text files use the policy

Doc/library/functools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ The :mod:`functools` module defines the following functions:
518518
... for i, elem in enumerate(arg):
519519
... print(i, elem)
520520

521-
:data:`types.UnionType` and :data:`typing.Union` can also be used::
521+
:class:`typing.Union` can also be used::
522522

523523
>>> @fun.register
524524
... def _(arg: int | float, verbose=False):
@@ -654,8 +654,8 @@ The :mod:`functools` module defines the following functions:
654654
The :func:`register` attribute now supports using type annotations.
655655

656656
.. versionchanged:: 3.11
657-
The :func:`register` attribute now supports :data:`types.UnionType`
658-
and :data:`typing.Union` as type annotations.
657+
The :func:`register` attribute now supports
658+
:class:`typing.Union` as a type annotation.
659659

660660

661661
.. class:: singledispatchmethod(func)

Doc/library/io.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,55 @@ Text I/O
11471147
It inherits from :class:`codecs.IncrementalDecoder`.
11481148

11491149

1150+
Static Typing
1151+
-------------
1152+
1153+
The following protocols can be used for annotating function and method
1154+
arguments for simple stream reading or writing operations. They are decorated
1155+
with :deco:`typing.runtime_checkable`.
1156+
1157+
.. class:: Reader[T]
1158+
1159+
Generic protocol for reading from a file or other input stream. ``T`` will
1160+
usually be :class:`str` or :class:`bytes`, but can be any type that is
1161+
read from the stream.
1162+
1163+
.. versionadded:: next
1164+
1165+
.. method:: read()
1166+
read(size, /)
1167+
1168+
Read data from the input stream and return it. If *size* is
1169+
specified, it should be an integer, and at most *size* items
1170+
(bytes/characters) will be read.
1171+
1172+
For example::
1173+
1174+
def read_it(reader: Reader[str]):
1175+
data = reader.read(11)
1176+
assert isinstance(data, str)
1177+
1178+
.. class:: Writer[T]
1179+
1180+
Generic protocol for writing to a file or other output stream. ``T`` will
1181+
usually be :class:`str` or :class:`bytes`, but can be any type that can be
1182+
written to the stream.
1183+
1184+
.. versionadded:: next
1185+
1186+
.. method:: write(data, /)
1187+
1188+
Write *data* to the output stream and return the number of items
1189+
(bytes/characters) written.
1190+
1191+
For example::
1192+
1193+
def write_binary(writer: Writer[bytes]):
1194+
writer.write(b"Hello world!\n")
1195+
1196+
See :ref:`typing-io` for other I/O related protocols and classes that can be
1197+
used for static type checking.
1198+
11501199
Performance
11511200
-----------
11521201

Doc/library/pdb.rst

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,34 @@ The debugger's prompt is ``(Pdb)``, which is the indicator that you are in debug
7575
arguments of the ``p`` command.
7676

7777

78+
.. program:: pdb
79+
7880
You can also invoke :mod:`pdb` from the command line to debug other scripts. For
7981
example::
8082

81-
python -m pdb myscript.py
83+
python -m pdb [-c command] (-m module | pyfile) [args ...]
8284

8385
When invoked as a module, pdb will automatically enter post-mortem debugging if
8486
the program being debugged exits abnormally. After post-mortem debugging (or
8587
after normal exit of the program), pdb will restart the program. Automatic
8688
restarting preserves pdb's state (such as breakpoints) and in most cases is more
8789
useful than quitting the debugger upon program's exit.
8890

89-
.. versionchanged:: 3.2
90-
Added the ``-c`` option to execute commands as if given
91-
in a :file:`.pdbrc` file; see :ref:`debugger-commands`.
91+
.. option:: -c, --command <command>
9292

93-
.. versionchanged:: 3.7
94-
Added the ``-m`` option to execute modules similar to the way
95-
``python -m`` does. As with a script, the debugger will pause execution just
96-
before the first line of the module.
93+
To execute commands as if given in a :file:`.pdbrc` file; see
94+
:ref:`debugger-commands`.
95+
96+
.. versionchanged:: 3.2
97+
Added the ``-c`` option.
98+
99+
.. option:: -m <module>
100+
101+
To execute modules similar to the way ``python -m`` does. As with a script,
102+
the debugger will pause execution just before the first line of the module.
103+
104+
.. versionchanged:: 3.7
105+
Added the ``-m`` option.
97106

98107
Typical usage to execute a statement under control of the debugger is::
99108

@@ -245,6 +254,10 @@ access further features, you have to do this yourself:
245254
.. versionadded:: 3.14
246255
Added the *mode* argument.
247256

257+
.. versionchanged:: 3.14
258+
Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will
259+
always stop the program at calling frame, ignoring the *skip* pattern (if any).
260+
248261
.. method:: run(statement, globals=None, locals=None)
249262
runeval(expression, globals=None, locals=None)
250263
runcall(function, *args, **kwds)

0 commit comments

Comments
 (0)