Skip to content

Commit eb11de8

Browse files
Merge branch 'main' into fix-pythongh-120524-racy-builtin-type-lifecycle
2 parents 7f85a2b + d9b4316 commit eb11de8

File tree

102 files changed

+1271
-380
lines changed

Some content is hidden

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

102 files changed

+1271
-380
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Doc/c-api/stable.rst @encukou
212212
**/*ensurepip* @pfmoore @pradyunsg
213213

214214
**/*idlelib* @terryjreedy
215+
/Doc/library/idle.rst @terryjreedy
215216

216217
**/*typing* @JelleZijlstra @AlexWaygood
217218

Doc/c-api/unicode.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,3 +1502,87 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
15021502
:c:func:`PyUnicode_InternInPlace`, returning either a new Unicode string
15031503
object that has been interned, or a new ("owned") reference to an earlier
15041504
interned string object with the same value.
1505+
1506+
PyUnicodeWriter
1507+
^^^^^^^^^^^^^^^
1508+
1509+
The :c:type:`PyUnicodeWriter` API can be used to create a Python :class:`str`
1510+
object.
1511+
1512+
.. versionadded:: 3.14
1513+
1514+
.. c:type:: PyUnicodeWriter
1515+
1516+
A Unicode writer instance.
1517+
1518+
The instance must be destroyed by :c:func:`PyUnicodeWriter_Finish` on
1519+
success, or :c:func:`PyUnicodeWriter_Discard` on error.
1520+
1521+
.. c:function:: PyUnicodeWriter* PyUnicodeWriter_Create(Py_ssize_t length)
1522+
1523+
Create a Unicode writer instance.
1524+
1525+
Set an exception and return ``NULL`` on error.
1526+
1527+
.. c:function:: PyObject* PyUnicodeWriter_Finish(PyUnicodeWriter *writer)
1528+
1529+
Return the final Python :class:`str` object and destroy the writer instance.
1530+
1531+
Set an exception and return ``NULL`` on error.
1532+
1533+
.. c:function:: void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
1534+
1535+
Discard the internal Unicode buffer and destroy the writer instance.
1536+
1537+
.. c:function:: int PyUnicodeWriter_WriteChar(PyUnicodeWriter *writer, Py_UCS4 ch)
1538+
1539+
Write the single Unicode character *ch* into *writer*.
1540+
1541+
On success, return ``0``.
1542+
On error, set an exception, leave the writer unchanged, and return ``-1``.
1543+
1544+
.. c:function:: int PyUnicodeWriter_WriteUTF8(PyUnicodeWriter *writer, const char *str, Py_ssize_t size)
1545+
1546+
Decode the string *str* from UTF-8 in strict mode and write the output into *writer*.
1547+
1548+
*size* is the string length in bytes. If *size* is equal to ``-1``, call
1549+
``strlen(str)`` to get the string length.
1550+
1551+
On success, return ``0``.
1552+
On error, set an exception, leave the writer unchanged, and return ``-1``.
1553+
1554+
To use a different error handler than ``strict``,
1555+
:c:func:`PyUnicode_DecodeUTF8` can be used with
1556+
:c:func:`PyUnicodeWriter_WriteStr`.
1557+
1558+
.. c:function:: int PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
1559+
1560+
Call :c:func:`PyObject_Str` on *obj* and write the output into *writer*.
1561+
1562+
On success, return ``0``.
1563+
On error, set an exception, leave the writer unchanged, and return ``-1``.
1564+
1565+
.. c:function:: int PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
1566+
1567+
Call :c:func:`PyObject_Repr` on *obj* and write the output into *writer*.
1568+
1569+
On success, return ``0``.
1570+
On error, set an exception, leave the writer unchanged, and return ``-1``.
1571+
1572+
.. c:function:: int PyUnicodeWriter_WriteSubstring(PyUnicodeWriter *writer, PyObject *str, Py_ssize_t start, Py_ssize_t end)
1573+
1574+
Write the substring ``str[start:end]`` into *writer*.
1575+
1576+
*str* must be Python :class:`str` object. *start* must be greater than or
1577+
equal to 0, and less than or equal to *end*. *end* must be less than or
1578+
equal to *str* length.
1579+
1580+
On success, return ``0``.
1581+
On error, set an exception, leave the writer unchanged, and return ``-1``.
1582+
1583+
.. c:function:: int PyUnicodeWriter_Format(PyUnicodeWriter *writer, const char *format, ...)
1584+
1585+
Similar to :c:func:`PyUnicode_FromFormat`, but write the output directly into *writer*.
1586+
1587+
On success, return ``0``.
1588+
On error, set an exception, leave the writer unchanged, and return ``-1``.

Doc/howto/enum.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _enum-howto:
2+
13
==========
24
Enum HOWTO
35
==========

Doc/howto/functional.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _functional-howto:
2+
13
********************************
24
Functional Programming HOWTO
35
********************************

Doc/howto/index.rst

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
Python HOWTOs
33
***************
44

5-
Python HOWTOs are documents that cover a single, specific topic,
6-
and attempt to cover it fairly completely. Modelled on the Linux
7-
Documentation Project's HOWTO collection, this collection is an
5+
Python HOWTOs are documents that cover a specific topic in-depth.
6+
Modeled on the Linux Documentation Project's HOWTO collection, this collection is an
87
effort to foster documentation that's more detailed than the
98
Python Library Reference.
109

11-
Currently, the HOWTOs are:
12-
1310
.. toctree::
1411
:maxdepth: 1
12+
:hidden:
1513

1614
cporting.rst
1715
curses.rst
@@ -35,3 +33,32 @@ Currently, the HOWTOs are:
3533
timerfd.rst
3634
mro.rst
3735

36+
General:
37+
38+
* :ref:`annotations-howto`
39+
* :ref:`argparse-tutorial`
40+
* :ref:`descriptorhowto`
41+
* :ref:`enum-howto`
42+
* :ref:`functional-howto`
43+
* :ref:`ipaddress-howto`
44+
* :ref:`logging-howto`
45+
* :ref:`logging-cookbook`
46+
* :ref:`regex-howto`
47+
* :ref:`sortinghowto`
48+
* :ref:`unicode-howto`
49+
* :ref:`urllib-howto`
50+
51+
Advanced development:
52+
53+
* :ref:`curses-howto`
54+
* :ref:`isolating-extensions-howto`
55+
* :ref:`python_2.3_mro`
56+
* :ref:`socket-howto`
57+
* :ref:`timerfd-howto`
58+
* :ref:`cporting-howto`
59+
60+
Debugging and profiling:
61+
62+
* :ref:`gdb`
63+
* :ref:`instrumentation`
64+
* :ref:`perf_profiling`

Doc/howto/logging.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _logging-howto:
2+
13
=============
24
Logging HOWTO
35
=============

Doc/library/ast.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,13 @@ Statements
891891
An assignment with a type annotation. ``target`` is a single node and can
892892
be a :class:`Name`, a :class:`Attribute` or a :class:`Subscript`.
893893
``annotation`` is the annotation, such as a :class:`Constant` or :class:`Name`
894-
node. ``value`` is a single optional node. ``simple`` is a boolean integer
895-
set to True for a :class:`Name` node in ``target`` that do not appear in
896-
between parenthesis and are hence pure names and not expressions.
894+
node. ``value`` is a single optional node.
895+
896+
``simple`` is always either 0 (indicating a "complex" target) or 1
897+
(indicating a "simple" target). A "simple" target consists solely of a
898+
:class:`Name` node that does not appear between parentheses; all other
899+
targets are considered complex. Only simple targets appear in
900+
the :attr:`__annotations__` dictionary of modules and classes.
897901

898902
.. doctest::
899903

Doc/library/enum.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ Data Types
629629
of two, starting with ``1``.
630630

631631
.. versionchanged:: 3.11 The *repr()* of zero-valued flags has changed. It
632-
is now::
632+
is now:
633633

634634
>>> Color(0) # doctest: +SKIP
635635
<Color: 0>

Doc/library/gzip.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,21 @@ The module defines the following items:
188188

189189
Compress the *data*, returning a :class:`bytes` object containing
190190
the compressed data. *compresslevel* and *mtime* have the same meaning as in
191-
the :class:`GzipFile` constructor above. When *mtime* is set to ``0``, this
192-
function is equivalent to :func:`zlib.compress` with *wbits* set to ``31``.
193-
The zlib function is faster.
191+
the :class:`GzipFile` constructor above.
194192

195193
.. versionadded:: 3.2
196194
.. versionchanged:: 3.8
197195
Added the *mtime* parameter for reproducible output.
198196
.. versionchanged:: 3.11
199197
Speed is improved by compressing all data at once instead of in a
200198
streamed fashion. Calls with *mtime* set to ``0`` are delegated to
201-
:func:`zlib.compress` for better speed.
199+
:func:`zlib.compress` for better speed. In this situation the
200+
output may contain a gzip header "OS" byte value other than 255
201+
"unknown" as supplied by the underlying zlib implementation.
202+
203+
.. versionchanged:: 3.13
204+
The gzip header OS byte is guaranteed to be set to 255 when this function
205+
is used as was the case in 3.10 and earlier.
202206

203207
.. function:: decompress(data)
204208

Doc/library/itertools.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ Iterator Arguments Results
5858
:func:`compress` data, selectors (d[0] if s[0]), (d[1] if s[1]), ... ``compress('ABCDEF', [1,0,1,0,1,1]) → A C E F``
5959
:func:`dropwhile` predicate, seq seq[n], seq[n+1], starting when predicate fails ``dropwhile(lambda x: x<5, [1,4,6,3,8]) → 6 3 8``
6060
:func:`filterfalse` predicate, seq elements of seq where predicate(elem) fails ``filterfalse(lambda x: x<5, [1,4,6,3,8]) → 6 8``
61-
:func:`groupby` iterable[, key] sub-iterators grouped by value of key(v)
61+
:func:`groupby` iterable[, key] sub-iterators grouped by value of key(v) ``groupby(['A','B','ABC'], len) → (1, A B) (3, ABC)``
6262
:func:`islice` seq, [start,] stop [, step] elements from seq[start:stop:step] ``islice('ABCDEFG', 2, None) → C D E F G``
6363
:func:`pairwise` iterable (p[0], p[1]), (p[1], p[2]) ``pairwise('ABCDEFG') → AB BC CD DE EF FG``
6464
:func:`starmap` func, seq func(\*seq[0]), func(\*seq[1]), ... ``starmap(pow, [(2,5), (3,2), (10,3)]) → 32 9 1000``
6565
:func:`takewhile` predicate, seq seq[0], seq[1], until predicate fails ``takewhile(lambda x: x<5, [1,4,6,3,8]) → 1 4``
66-
:func:`tee` it, n it1, it2, ... itn splits one iterator into n
66+
:func:`tee` it, n it1, it2, ... itn splits one iterator into n ``tee('ABC', 2) → A B C, A B C``
6767
:func:`zip_longest` p, q, ... (p[0], q[0]), (p[1], q[1]), ... ``zip_longest('ABCD', 'xy', fillvalue='-') → Ax By C- D-``
6868
============================ ============================ ================================================= =============================================================
6969

Doc/library/ssl.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,19 @@ to speed up repeated connections from the same clients.
14721472
:data:`PROTOCOL_TLS`, :data:`PROTOCOL_TLS_CLIENT`, and
14731473
:data:`PROTOCOL_TLS_SERVER` use TLS 1.2 as minimum TLS version.
14741474

1475+
.. note::
1476+
1477+
:class:`SSLContext` only supports limited mutation once it has been used
1478+
by a connection. Adding new certificates to the internal trust store is
1479+
allowed, but changing ciphers, verification settings, or mTLS
1480+
certificates may result in surprising behavior.
1481+
1482+
.. note::
1483+
1484+
:class:`SSLContext` is designed to be shared and used by multiple
1485+
connections.
1486+
Thus, it is thread-safe as long as it is not reconfigured after being
1487+
used by a connection.
14751488

14761489
:class:`SSLContext` objects have the following methods and attributes:
14771490

Doc/library/symtable.rst

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,74 @@ Generating Symbol Tables
3131
Examining Symbol Tables
3232
-----------------------
3333

34+
.. class:: SymbolTableType
35+
36+
An enumeration indicating the type of a :class:`SymbolTable` object.
37+
38+
.. attribute:: MODULE
39+
:value: "module"
40+
41+
Used for the symbol table of a module.
42+
43+
.. attribute:: FUNCTION
44+
:value: "function"
45+
46+
Used for the symbol table of a function.
47+
48+
.. attribute:: CLASS
49+
:value: "class"
50+
51+
Used for the symbol table of a class.
52+
53+
The following members refer to different flavors of
54+
:ref:`annotation scopes <annotation-scopes>`.
55+
56+
.. attribute:: ANNOTATION
57+
:value: "annotation"
58+
59+
Used for annotations if ``from __future__ import annotations`` is active.
60+
61+
.. attribute:: TYPE_ALIAS
62+
:value: "type alias"
63+
64+
Used for the symbol table of :keyword:`type` constructions.
65+
66+
.. attribute:: TYPE_PARAMETERS
67+
:value: "type parameters"
68+
69+
Used for the symbol table of :ref:`generic functions <generic-functions>`
70+
or :ref:`generic classes <generic-classes>`.
71+
72+
.. attribute:: TYPE_VARIABLE
73+
:value: "type variable"
74+
75+
Used for the symbol table of the bound, the constraint tuple or the
76+
default value of a single type variable in the formal sense, i.e.,
77+
a TypeVar, a TypeVarTuple or a ParamSpec object (the latter two do
78+
not support a bound or a constraint tuple).
79+
80+
.. versionadded:: 3.13
81+
3482
.. class:: SymbolTable
3583

3684
A namespace table for a block. The constructor is not public.
3785

3886
.. method:: get_type()
3987

40-
Return the type of the symbol table. Possible values are ``'class'``,
41-
``'module'``, ``'function'``, ``'annotation'``, ``'TypeVar bound'``,
42-
``'type alias'``, and ``'type parameter'``. The latter four refer to
43-
different flavors of :ref:`annotation scopes <annotation-scopes>`.
88+
Return the type of the symbol table. Possible values are members
89+
of the :class:`SymbolTableType` enumeration.
4490

4591
.. versionchanged:: 3.12
4692
Added ``'annotation'``, ``'TypeVar bound'``, ``'type alias'``,
4793
and ``'type parameter'`` as possible return values.
4894

95+
.. versionchanged:: 3.13
96+
Return values are members of the :class:`SymbolTableType` enumeration.
97+
98+
The exact values of the returned string may change in the future,
99+
and thus, it is recommended to use :class:`SymbolTableType` members
100+
instead of hard-coded strings.
101+
49102
.. method:: get_id()
50103

51104
Return the table's identifier.

Doc/library/typing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,8 @@ These can be used as types in annotations. They all support subscription using
14541454
to write such functions in a type-safe manner.
14551455

14561456
If a ``TypeIs`` function is a class or instance method, then the type in
1457-
``TypeIs`` maps to the type of the second parameter after ``cls`` or
1458-
``self``.
1457+
``TypeIs`` maps to the type of the second parameter (after ``cls`` or
1458+
``self``).
14591459

14601460
In short, the form ``def foo(arg: TypeA) -> TypeIs[TypeB]: ...``,
14611461
means that if ``foo(arg)`` returns ``True``, then ``arg`` is an instance

Doc/reference/simple_stmts.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,18 @@ statement, of a variable or attribute annotation and an optional assignment stat
333333

334334
The difference from normal :ref:`assignment` is that only a single target is allowed.
335335

336-
For simple names as assignment targets, if in class or module scope,
336+
The assignment target is considered "simple" if it consists of a single
337+
name that is not enclosed in parentheses.
338+
For simple assignment targets, if in class or module scope,
337339
the annotations are evaluated and stored in a special class or module
338340
attribute :attr:`__annotations__`
339341
that is a dictionary mapping from variable names (mangled if private) to
340342
evaluated annotations. This attribute is writable and is automatically
341343
created at the start of class or module body execution, if annotations
342344
are found statically.
343345

344-
For expressions as assignment targets, the annotations are evaluated if
346+
If the assignment target is not simple (an attribute, subscript node, or
347+
parenthesized name), the annotation is evaluated if
345348
in class or module scope, but not stored.
346349

347350
If a name is annotated in a function scope, then this name is local for

0 commit comments

Comments
 (0)