Skip to content

Commit 268c11a

Browse files
authored
Merge branch 'main' into fix-gh-153962-internal-poll-oserror
2 parents ba1f9aa + 20b50f8 commit 268c11a

61 files changed

Lines changed: 2330 additions & 504 deletions

Some content is hidden

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

Doc/c-api/exceptions.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,12 @@ Querying the error indicator
499499
.. c:function:: void PyErr_SetRaisedException(PyObject *exc)
500500
501501
Set *exc* as the exception currently being raised,
502-
clearing the existing exception if one is set.
502+
clearing the existing exception if one is set. If *exc* is ``NULL``,
503+
just clear the existing exception.
503504
504-
.. warning::
505+
*exc* must be a valid exception or ``NULL``.
505506
506-
This call ":term:`steals <steal>`" a reference to *exc*,
507-
which must be a valid exception.
507+
This call ":term:`steals <steal>`" a reference to *exc*.
508508
509509
.. versionadded:: 3.12
510510

Doc/c-api/frame.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,62 @@ Unless using :pep:`523`, you will not need this.
243243
Return the currently executing line number, or -1 if there is no line number.
244244
245245
.. versionadded:: 3.12
246+
247+
248+
.. c:var:: const PyTypeObject *PyUnstable_ExecutableKinds
249+
250+
An array of executable kinds (executor types) for frames, used for internal
251+
debugging and tracing.
252+
253+
Tools like debuggers and profilers can use this to identify the type of execution
254+
context associated with a frame (such as to filter out internal frames).
255+
The entries are indexed by the following constants:
256+
257+
.. list-table::
258+
:header-rows: 1
259+
:widths: auto
260+
261+
* - Constant
262+
- Description
263+
* - .. c:macro:: PyUnstable_EXECUTABLE_KIND_SKIP
264+
- The frame is internal (For example: inlined) and should be skipped by tools.
265+
* - .. c:macro:: PyUnstable_EXECUTABLE_KIND_PY_FUNCTION
266+
- The frame corresponds to a standard Python function.
267+
* - .. c:macro:: PyUnstable_EXECUTABLE_KIND_BUILTIN_FUNCTION
268+
- The frame corresponds to a function defined in native code.
269+
* - .. c:macro:: PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR
270+
- The frame corresponds to a method on a class instance.
271+
272+
However, Python's C API lacks a function to read the executable kind from
273+
a frame. Instead, use this recipe:
274+
275+
.. code-block:: c
276+
277+
int
278+
get_executable_kind(PyFrameObject *frame)
279+
{
280+
_PyInterpreterFrame *f = frame->f_frame;
281+
PyObject *exec = PyStackRef_AsPyObjectBorrow(f->f_executable);
282+
283+
if (PyCode_Check(exec)) {
284+
return PyUnstable_EXECUTABLE_KIND_PY_FUNCTION;
285+
}
286+
if (PyMethod_Check(exec)) {
287+
return PyUnstable_EXECUTABLE_KIND_BUILTIN_FUNCTION;
288+
}
289+
if (Py_IS_TYPE(exec, &PyMethodDescr_Type)) {
290+
return PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR;
291+
}
292+
293+
return PyUnstable_EXECUTABLE_KIND_SKIP;
294+
}
295+
296+
.. versionadded:: 3.13
297+
298+
299+
.. c:macro:: PyUnstable_EXECUTABLE_KINDS
300+
301+
The number of entries in :c:data:`PyUnstable_ExecutableKinds`.
302+
303+
.. versionadded:: 3.13
304+

Doc/c-api/veryhigh.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,125 @@ the same library that the Python runtime is using.
343343
:py:mod:`!ast` Python module, which exports these constants under
344344
the same names.
345345
346+
.. rubric:: Low-level flags
347+
348+
The following flags and masks serve narrow needs of the standard
349+
library and interactive interpreters. Code outside the standard
350+
library rarely has a reason to use them. They are considered
351+
implementation details and may change at any time.
352+
353+
.. c:macro:: PyCF_ALLOW_INCOMPLETE_INPUT
354+
355+
This flag is a private interface between the compiler and the
356+
:mod:`codeop` module. Do not use it; its behavior is unsupported
357+
and may change without warning.
358+
359+
With this flag set, when compilation fails because the source text
360+
ends where more input is expected, for example in the middle of an
361+
indented block or an unterminated string literal, the error raised
362+
is the undocumented ``_IncompleteInputError``, a subclass of
363+
:exc:`SyntaxError`. The :mod:`codeop` module sets this flag,
364+
together with :c:macro:`PyCF_DONT_IMPLY_DEDENT`, to tell input
365+
that is incomplete apart from input with a real syntax error, so
366+
that interactive interpreters know when to prompt for another
367+
line instead of reporting an error.
368+
369+
.. versionadded:: 3.11
370+
371+
.. c:macro:: PyCF_DONT_IMPLY_DEDENT
372+
373+
By default, when compiling with the :c:var:`Py_single_input` start
374+
symbol, reaching the end of the source text implicitly closes any
375+
open indented blocks. With this flag set, open blocks are only
376+
closed if the last line of the source ends with a newline; otherwise,
377+
compilation fails with a :exc:`SyntaxError`:
378+
379+
.. code-block:: c
380+
381+
PyCompilerFlags flags = {
382+
.cf_flags = 0,
383+
.cf_feature_version = PY_MINOR_VERSION,
384+
};
385+
const char *source = "if a:\n pass";
386+
387+
/* The "if" block is closed implicitly;
388+
this returns a code object: */
389+
Py_CompileStringFlags(source, "<input>", Py_single_input, &flags);
390+
391+
/* With the flag, this fails with a SyntaxError,
392+
because the last line does not end with a newline: */
393+
flags.cf_flags = PyCF_DONT_IMPLY_DEDENT;
394+
Py_CompileStringFlags(source, "<input>", Py_single_input, &flags);
395+
396+
The :mod:`codeop` module uses this flag to detect incomplete
397+
interactive input. While the user is still typing inside an
398+
indented block, the source does not yet end with a newline, so it
399+
fails to compile and the user is prompted for another line.
400+
401+
.. c:macro:: PyCF_IGNORE_COOKIE
402+
403+
Read the source text as UTF-8, ignoring its :pep:`263` encoding
404+
declaration ("coding cookie"), if any:
405+
406+
.. code-block:: c
407+
408+
PyCompilerFlags flags = {
409+
.cf_flags = 0,
410+
.cf_feature_version = PY_MINOR_VERSION,
411+
};
412+
const char *source = "# coding: latin-1\ns = '\xe9'\n";
413+
414+
/* The coding cookie is honored: byte 0xE9 is decoded as
415+
Latin-1, and this returns a code object that sets s to "é": */
416+
Py_CompileStringFlags(source, "<input>", Py_file_input, &flags);
417+
418+
/* With the flag, the cookie is ignored and compilation fails
419+
with a SyntaxError, because 0xE9 is not valid UTF-8: */
420+
flags.cf_flags = PyCF_IGNORE_COOKIE;
421+
Py_CompileStringFlags(source, "<input>", Py_file_input, &flags);
422+
423+
The :func:`compile`, :func:`eval` and :func:`exec` built-in functions
424+
set this flag when the source is a :class:`str` object, because they
425+
pass the text to the parser encoded as UTF-8.
426+
427+
.. c:macro:: PyCF_SOURCE_IS_UTF8
428+
429+
Mark the source text as known to be UTF-8 encoded.
430+
The :func:`compile`, :func:`eval` and :func:`exec` built-in functions
431+
set this flag, but it currently has no effect.
432+
346433
The "``PyCF``" flags above can be combined with "``CO_FUTURE``" flags such
347434
as :c:macro:`CO_FUTURE_ANNOTATIONS` to enable features normally
348435
selectable using :ref:`future statements <future>`.
349436
See :ref:`c_codeobject_flags` for a complete list.
350437
438+
The following masks combine several flags:
439+
440+
.. c:macro:: PyCF_MASK
441+
442+
Bitmask of all ``CO_FUTURE`` flags (see :ref:`c_codeobject_flags`),
443+
which select features normally enabled by
444+
:ref:`future statements <future>`.
445+
When code compiled with a ``PyCompilerFlags *flags`` argument
446+
contains a ``from __future__ import`` statement, the flag for the
447+
imported feature is added to *flags*, so that code executed later
448+
in the same context inherits it.
449+
450+
.. c:macro:: PyCF_MASK_OBSOLETE
451+
452+
Do not use this mask in new code. It is kept only so that old
453+
code passing its flags to :func:`compile` keeps working.
454+
455+
Bitmask of flags for obsolete future features that no longer
456+
have any effect.
457+
458+
.. c:macro:: PyCF_COMPILE_MASK
459+
460+
Bitmask of all ``PyCF`` flags that change how the source is
461+
compiled, such as :c:macro:`PyCF_ONLY_AST`.
462+
The :func:`compile` built-in function uses this mask to validate
463+
its *flags* argument.
464+
351465
352466
.. _start-symbols:
353467

Doc/howto/abi3t-migration.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Migrating to Stable ABI for free threading (``abi3t``)
88

99
Starting with the 3.15 release, CPython supports a variant of the Stable ABI
1010
that supports :term:`free-threaded <free threading>` Python:
11-
Stable ABI for Free-Threaded Builds, or ``abi3t`` for short.
11+
the Stable ABI for Free-Threaded Builds, or ``abi3t`` for short.
1212
This document describes how to adapt C API extensions to support free threading.
1313

1414
Why do this
1515
===========
1616

17-
The typical reason to use Stable ABI is to reduce the number of artifacts that
18-
you need to build and distribute for each version of your library.
17+
The typical reason to use the Stable ABI is to reduce the number of artifacts
18+
that you need to build and distribute for each version of your library.
1919

2020
Without the Stable ABI, you must build a separate shared library, and typically
2121
a *wheel* distribution, for each feature version of CPython you wish
@@ -87,16 +87,16 @@ builds; even the 3.15+ ones that this table "attributes" to ``abi3t``.)
8787
Why *not* do this
8888
-----------------
8989

90-
There are two main downsides to Stable ABI.
90+
There are two main downsides to the Stable ABI.
9191

92-
First, you extension may become slower, since Stable ABI prioritizes
92+
First, your extension may become slower, since the Stable ABI prioritizes
9393
compatibility over performance.
9494
The difference is usually not noticeable, and often can be mitigated by
9595
using the same source to build both a Stable ABI build and a few
9696
version-specific ones for "tier 1" CPython versions.
9797

9898
Second, not all of the C API is available.
99-
Extensions need to be ported to build for Stable ABI, which may be difficult
99+
Extensions need to be ported to build for the Stable ABI, which may be difficult
100100
or, in rare cases, impossible.
101101

102102
Specifically, ``abi3t`` requires APIs added in CPython 3.15.
@@ -127,15 +127,15 @@ Prerequisites
127127
This guide assumes that you have an extension written directly in C (or C++),
128128
which you want to port to ``abi3t``.
129129

130-
If your extenstion uses a code generator (like Cython) or language binding
130+
If your extension uses a code generator (like Cython) or language binding
131131
(like PyO3), it's best to wait until that tool has support for ``abi3t``.
132132
If you maintain such a tool, you might be able to adapt the instructions
133133
here for your tool.
134134

135135
Non-free-threaded Stable ABI
136136
----------------------------
137137

138-
Your extension should support the Stable ABI (``abi3t``).
138+
Your extension should support the non-free-threaded Stable ABI (``abi3``).
139139
If not, either port it first, or follow this guide but be prepared to fix
140140
issues it does not mention.
141141

@@ -183,7 +183,7 @@ following just after ``#include <Python.h>``::
183183
#error "abi3t define is not set!"
184184
#endif
185185

186-
This should result in a different error than "``abt3t`` define is not set".
186+
This should result in a different error than "``abi3t`` define is not set".
187187

188188
.. note::
189189

@@ -705,7 +705,7 @@ Testing
705705
Note that when you build an extension compatible with multiple versions of
706706
CPython, you should always *test* it with each version it supports (for
707707
example, 3.15, 3.16, and so on).
708-
Stable ABI only guarantees *ABI* compatibility; there may also be behavior
708+
The Stable ABI only guarantees *ABI* compatibility; there may also be behavior
709709
changes -- both intentional ones (covered by :pep:`387`) and bugs.
710710

711711
Be sure to run tests on both free-threaded and non-free-threaded builds

Doc/howto/logging-cookbook.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ Subclass ``QueueListener``
19551955
class NNGSocketListener(logging.handlers.QueueListener):
19561956
19571957
def __init__(self, uri, /, *handlers, **kwargs):
1958-
# Have a timeout for interruptability, and open a
1958+
# Have a timeout for interruptibility, and open a
19591959
# subscriber socket
19601960
socket = pynng.Sub0(listen=uri, recv_timeout=500)
19611961
# The b'' subscription matches all topics

Doc/library/curses.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@ Reading window contents
13211321
The bottom 8 bits are the character proper and the upper bits are the attributes;
13221322
extract them with the :data:`A_CHARTEXT` and :data:`A_ATTRIBUTES` bit-masks,
13231323
and the color pair with :func:`pair_number`.
1324+
The character byte is the locale-encoded byte of the cell's character,
1325+
consistent with :meth:`instr`.
13241326
It cannot represent a cell holding combining characters, a character that does
13251327
not fit in a single byte, or a color pair outside the :func:`color_pair`
13261328
range; use :meth:`in_wch` for those, which returns it as a :class:`complexchar`.

Doc/library/datatypes.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ The modules described in this chapter provide a variety of specialized data
88
types such as dates and times, fixed-type arrays, heap queues, double-ended
99
queues, and enumerations.
1010

11-
Python also provides some built-in data types, in particular,
12-
:class:`dict`, :class:`list`, :class:`set` and :class:`frozenset`, and
13-
:class:`tuple`. The :class:`str` class is used to hold
11+
Python also provides :ref:`some built-in data types <bltin-types>`, in particular,
12+
:class:`list`, :class:`tuple`, :class:`dict`, :class:`frozendict`,
13+
:class:`set`, and :class:`frozenset`.
14+
The :class:`str` class is used to hold
1415
Unicode strings, and the :class:`bytes` and :class:`bytearray` classes are used
1516
to hold binary data.
1617

Doc/library/difflib.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
8585
with inter-line and intra-line change highlights. The table can be generated in
8686
either full or contextual difference mode.
8787

88+
.. warning::
89+
90+
The trailing newlines get stripped before the diff, so the result can be
91+
incomplete. See :gh:`71896` for details.
92+
8893
The constructor for this class is:
8994

9095

Doc/library/getopt.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ exception:
6262
option ``--fo`` will match as ``--foo``, but ``--f`` will
6363
not match uniquely, so :exc:`GetoptError` will be raised.
6464

65+
If *longopts* is a string it gets treated as a list of a single element.
66+
6567
The return value consists of two elements: the first is a list of ``(option,
6668
value)`` pairs; the second is the list of program arguments left after the
6769
option list was stripped (this is a trailing slice of *args*). Each

Doc/library/mimetypes.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ behavior of the module.
116116
Previously, Windows registry settings were ignored.
117117

118118

119-
.. function:: read_mime_types(filename)
119+
.. function:: read_mime_types(file)
120120

121-
Load the type map given in the file *filename*, if it exists. The type map is
122-
returned as a dictionary mapping filename extensions, including the leading dot
123-
(``'.'``), to strings of the form ``'type/subtype'``. If the file *filename*
124-
does not exist or cannot be read, ``None`` is returned.
121+
Load the type map given in the file named by *file*, if it exists. *file*
122+
must be a string specifying the name of the file to read. The type map is
123+
returned as a dictionary mapping file extensions, including the leading dot
124+
(``'.'``), to strings of the form ``'type/subtype'``. If the file does not
125+
exist or cannot be read, ``None`` is returned.
125126

126127

127128
.. function:: add_type(type, ext, strict=True)

0 commit comments

Comments
 (0)