Skip to content

Commit 985b871

Browse files
authored
Merge branch 'main' into docs-readline-repl
2 parents c807573 + d7e12a3 commit 985b871

26 files changed

+776
-35
lines changed

Doc/library/ssl.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,13 @@ SSL sockets also have the following additional methods and attributes:
12901290

12911291
.. versionadded:: 3.5
12921292

1293+
.. method:: SSLSocket.group()
1294+
1295+
Return the group used for doing key agreement on this connection. If no
1296+
connection has been established, returns ``None``.
1297+
1298+
.. versionadded:: next
1299+
12931300
.. method:: SSLSocket.compression()
12941301

12951302
Return the compression algorithm being used as a string, or ``None``
@@ -1647,6 +1654,25 @@ to speed up repeated connections from the same clients.
16471654

16481655
.. versionadded:: 3.6
16491656

1657+
.. method:: SSLContext.get_groups(*, include_aliases=False)
1658+
1659+
Get a list of groups implemented for key agreement, taking into
1660+
account the current TLS :attr:`~SSLContext.minimum_version` and
1661+
:attr:`~SSLContext.maximum_version` values. For example::
1662+
1663+
>>> ctx = ssl.create_default_context()
1664+
>>> ctx.minimum_version = ssl.TLSVersion.TLSv1_3
1665+
>>> ctx.maximum_version = ssl.TLSVersion.TLSv1_3
1666+
>>> ctx.get_groups() # doctest: +SKIP
1667+
['secp256r1', 'secp384r1', 'secp521r1', 'x25519', 'x448', ...]
1668+
1669+
By default, this method returns only the preferred IANA names for the
1670+
available groups. However, if the ``include_aliases`` parameter is set to
1671+
:const:`True` this method will also return any associated aliases such as
1672+
the ECDH curve names supported in older versions of OpenSSL.
1673+
1674+
.. versionadded:: next
1675+
16501676
.. method:: SSLContext.set_default_verify_paths()
16511677

16521678
Load a set of default "certification authority" (CA) certificates from
@@ -1672,6 +1698,19 @@ to speed up repeated connections from the same clients.
16721698
TLS 1.3 cipher suites cannot be disabled with
16731699
:meth:`~SSLContext.set_ciphers`.
16741700

1701+
.. method:: SSLContext.set_groups(groups)
1702+
1703+
Set the groups allowed for key agreement for sockets created with this
1704+
context. It should be a string in the `OpenSSL group list format
1705+
<https://docs.openssl.org/master/man3/SSL_CTX_set1_groups_list/>`_.
1706+
1707+
.. note::
1708+
1709+
When connected, the :meth:`SSLSocket.group` method of SSL sockets will
1710+
return the group used for key agreement on that connection.
1711+
1712+
.. versionadded:: next
1713+
16751714
.. method:: SSLContext.set_alpn_protocols(protocols)
16761715

16771716
Specify which protocols the socket should advertise during the SSL/TLS

Doc/reference/compound_stmts.rst

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,9 @@ is equivalent to ::
14211421
class Foo(object):
14221422
pass
14231423

1424+
There may be one or more base classes; see :ref:`multiple-inheritance` below for more
1425+
information.
1426+
14241427
The class's suite is then executed in a new execution frame (see :ref:`naming`),
14251428
using a newly created local namespace and the original global namespace.
14261429
(Usually, the suite contains mostly function definitions.) When the class's
@@ -1490,6 +1493,119 @@ can be used to create instance variables with different implementation details.
14901493
were introduced in :pep:`318`.
14911494

14921495

1496+
.. _multiple-inheritance:
1497+
1498+
Multiple inheritance
1499+
--------------------
1500+
1501+
Python classes may have multiple base classes, a technique known as
1502+
*multiple inheritance*. The base classes are specified in the class definition
1503+
by listing them in parentheses after the class name, separated by commas.
1504+
For example, the following class definition:
1505+
1506+
.. doctest::
1507+
1508+
>>> class A: pass
1509+
>>> class B: pass
1510+
>>> class C(A, B): pass
1511+
1512+
defines a class ``C`` that inherits from classes ``A`` and ``B``.
1513+
1514+
The :term:`method resolution order` (MRO) is the order in which base classes are
1515+
searched when looking up an attribute on a class. See :ref:`python_2.3_mro` for a
1516+
description of how Python determines the MRO for a class.
1517+
1518+
Multiple inheritance is not always allowed. Attempting to define a class with multiple
1519+
inheritance will raise an error if one of the bases does not allow subclassing, if a consistent MRO
1520+
cannot be created, if no valid metaclass can be determined, or if there is an instance
1521+
layout conflict. We'll discuss each of these in turn.
1522+
1523+
First, all base classes must allow subclassing. While most classes allow subclassing,
1524+
some built-in classes do not, such as :class:`bool`:
1525+
1526+
.. doctest::
1527+
1528+
>>> class SubBool(bool): # TypeError
1529+
... pass
1530+
Traceback (most recent call last):
1531+
...
1532+
TypeError: type 'bool' is not an acceptable base type
1533+
1534+
In the resolved MRO of a class, the class's bases appear in the order they were
1535+
specified in the class's bases list. Additionally, the MRO always lists a child
1536+
class before any of its bases. A class definition will fail if it is impossible to
1537+
resolve a consistent MRO that satisfies these rules from the list of bases provided:
1538+
1539+
.. doctest::
1540+
1541+
>>> class Base: pass
1542+
>>> class Child(Base): pass
1543+
>>> class Grandchild(Base, Child): pass # TypeError
1544+
Traceback (most recent call last):
1545+
...
1546+
TypeError: Cannot create a consistent method resolution order (MRO) for bases Base, Child
1547+
1548+
In the MRO of ``Grandchild``, ``Base`` must appear before ``Child`` because it is first
1549+
in the base class list, but it must also appear after ``Child`` because it is a parent of
1550+
``Child``. This is a contradiction, so the class cannot be defined.
1551+
1552+
If some of the bases have a custom :term:`metaclass`, the metaclass of the resulting class
1553+
is chosen among the metaclasses of the bases and the explicitly specified metaclass of the
1554+
child class. It must be a metaclass that is a subclass of
1555+
all other candidate metaclasses. If no such metaclass exists among the candidates,
1556+
the class cannot be created, as explained in :ref:`metaclass-determination`.
1557+
1558+
Finally, the instance layouts of the bases must be compatible. This means that it must be
1559+
possible to compute a *solid base* for the class. Exactly which classes are solid bases
1560+
depends on the Python implementation.
1561+
1562+
.. impl-detail::
1563+
1564+
In CPython, a class is a solid base if it has a
1565+
nonempty :attr:`~object.__slots__` definition.
1566+
Many but not all classes defined in C are also solid bases, including most
1567+
builtins (such as :class:`int` or :class:`BaseException`)
1568+
but excluding most concrete :class:`Exception` classes. Generally, a C class
1569+
is a solid base if its underlying struct is different in size from its base class.
1570+
1571+
Every class has a solid base. :class:`object`, the base class, has itself as its solid base.
1572+
If there is a single base, the child class's solid base is that class if it is a solid base,
1573+
or else the base class's solid base. If there are multiple bases, we first find the solid base
1574+
for each base class to produce a list of candidate solid bases. If there is a unique solid base
1575+
that is a subclass of all others, then that class is the solid base. Otherwise, class creation
1576+
fails.
1577+
1578+
Example:
1579+
1580+
.. doctest::
1581+
1582+
>>> class Solid1:
1583+
... __slots__ = ("solid1",)
1584+
>>>
1585+
>>> class Solid2:
1586+
... __slots__ = ("solid2",)
1587+
>>>
1588+
>>> class SolidChild(Solid1):
1589+
... __slots__ = ("solid_child",)
1590+
>>>
1591+
>>> class C1: # solid base is `object`
1592+
... pass
1593+
>>>
1594+
>>> # OK: solid bases are `Solid1` and `object`, and `Solid1` is a subclass of `object`.
1595+
>>> class C2(Solid1, C1): # solid base is `Solid1`
1596+
... pass
1597+
>>>
1598+
>>> # OK: solid bases are `SolidChild` and `Solid1`, and `SolidChild` is a subclass of `Solid1`.
1599+
>>> class C3(SolidChild, Solid1): # solid base is `SolidChild`
1600+
... pass
1601+
>>>
1602+
>>> # Error: solid bases are `Solid1` and `Solid2`, but neither is a subclass of the other.
1603+
>>> class C4(Solid1, Solid2): # error: no single solid base
1604+
... pass
1605+
Traceback (most recent call last):
1606+
...
1607+
TypeError: multiple bases have instance lay-out conflict
1608+
14931609
.. _async:
14941610

14951611
Coroutines

Doc/reference/datamodel.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,7 @@ Notes on using *__slots__*:
26292629
* :attr:`~object.__class__` assignment works only if both classes have the
26302630
same *__slots__*.
26312631

2632-
* :ref:`Multiple inheritance <tut-multiple>` with multiple slotted parent
2632+
* :ref:`Multiple inheritance <multiple-inheritance>` with multiple slotted parent
26332633
classes can be used,
26342634
but only one parent is allowed to have attributes created by slots
26352635
(the other bases must have empty slot layouts) - violations raise
@@ -2779,6 +2779,8 @@ Resolving MRO entries
27792779
Core support for typing module and generic types.
27802780

27812781

2782+
.. _metaclass-determination:
2783+
27822784
Determining the appropriate metaclass
27832785
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27842786
.. index::

Doc/tutorial/classes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ Taken together, these properties make it possible to design reliable and
663663
extensible classes with multiple inheritance. For more detail, see
664664
:ref:`python_2.3_mro`.
665665

666+
In some cases multiple inheritance is not allowed; see :ref:`multiple-inheritance`
667+
for details.
668+
666669

667670
.. _tut-private:
668671

Doc/whatsnew/3.14.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,18 @@ The behavior of :func:`!gc.collect` changes slightly:
10811081

10821082
(Contributed by Mark Shannon in :gh:`108362`.)
10831083

1084+
Platform support
1085+
================
1086+
1087+
* :pep:`776`: Emscripten is now an officially supported platform at
1088+
:pep:`tier 3 <11#tier-3>`. As a part of this effort, more than 25 bugs in
1089+
`Emscripten libc`__ were fixed. Emscripten now includes support
1090+
for :mod:`ctypes`, :mod:`termios`, and :mod:`fcntl`, as well as
1091+
experimental support for :ref:`PyREPL <tut-interactive>`.
1092+
1093+
(Contributed by R. Hood Chatham in :gh:`127146`, :gh:`127683`, and :gh:`136931`.)
1094+
1095+
__ https://emscripten.org/docs/porting/emscripten-runtime-environment.html
10841096

10851097
Other language changes
10861098
======================

Doc/whatsnew/3.15.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,24 @@ ssl
300300
supports "External PSKs" in TLSv1.3, as described in RFC 9258.
301301
(Contributed by Will Childs-Klein in :gh:`133624`.)
302302

303+
* Added new methods for managing groups used for SSL key agreement
304+
305+
* :meth:`ssl.SSLContext.set_groups` sets the groups allowed for doing
306+
key agreement, extending the previous
307+
:meth:`ssl.SSLContext.set_ecdh_curve` method.
308+
This new API provides the ability to list multiple groups and
309+
supports fixed-field and post-quantum groups in addition to ECDH
310+
curves. This method can also be used to control what key shares
311+
are sent in the TLS handshake.
312+
* :meth:`ssl.SSLSocket.group` returns the group selected for doing key
313+
agreement on the current connection after the TLS handshake completes.
314+
This call requires OpenSSL 3.2 or later.
315+
* :meth:`ssl.SSLContext.get_groups` returns a list of all available key
316+
agreement groups compatible with the minimum and maximum TLS versions
317+
currently set in the context. This call requires OpenSSL 3.5 or later.
318+
319+
(Contributed by Ron Frederick in :gh:`136306`)
320+
303321

304322
tarfile
305323
-------

Include/internal/pycore_dict.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ extern Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t has
113113
extern Py_ssize_t _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
114114
extern Py_ssize_t _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr);
115115

116+
extern int _PyDict_GetMethodStackRef(PyDictObject *dict, PyObject *name, _PyStackRef *method);
117+
116118
extern Py_ssize_t _PyDict_LookupIndex(PyDictObject *, PyObject *);
117119
extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
118120

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ struct _Py_global_strings {
496496
STRUCT_FOR_ID(imag)
497497
STRUCT_FOR_ID(importlib)
498498
STRUCT_FOR_ID(in_fd)
499+
STRUCT_FOR_ID(include_aliases)
499500
STRUCT_FOR_ID(incoming)
500501
STRUCT_FOR_ID(index)
501502
STRUCT_FOR_ID(indexgroup)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)