Skip to content

Commit 73671ff

Browse files
committed
gh-158285: Deprecate socket.ALG_SET_PUBKEY, ALG_OP_SIGN and ALG_OP_VERIFY
They are libkcapi's own values and were never defined by the Linux kernel, which uses the value of ALG_SET_PUBKEY for ALG_SET_DRBG_ENTROPY. socket no longer re-exports them from _socket, and accessing them through socket emits a DeprecationWarning. Removal is slated for 3.21.
1 parent 3330712 commit 73671ff

6 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎Doc/deprecations/pending-removal-in-3.21.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Pending removal in Python 3.21
1818
* The ``dims`` property of ``ast.Tuple`` will be removed in Python 3.21. Use
1919
the ``ast.Tuple.elts`` property instead.
2020

21+
* :mod:`socket`:
22+
23+
* ``ALG_SET_PUBKEY``, ``ALG_OP_SIGN`` and ``ALG_OP_VERIFY`` will be removed
24+
in Python 3.21. They were never defined by the Linux kernel.
25+
2126
* :mod:`struct`:
2227

2328
* Soft-deprecated since Python 3.15, using ``'F'`` and ``'D'`` type codes are now

‎Doc/library/socket.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,11 @@ The AF_* and SOCK_* constants are now :class:`AddressFamily` and
637637

638638
.. versionadded:: 3.6
639639

640+
.. deprecated-removed:: next 3.21
641+
``ALG_SET_PUBKEY``, ``ALG_OP_SIGN`` and ``ALG_OP_VERIFY``.
642+
They are libkcapi's own values and were never defined by the Linux kernel,
643+
which uses the value of ``ALG_SET_PUBKEY`` for ``ALG_SET_DRBG_ENTROPY``.
644+
640645

641646
.. data:: AF_VSOCK
642647
IOCTL_VM_SOCKETS_GET_LOCAL_CID

‎Doc/whatsnew/3.16.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,14 @@ New deprecations
963963
3.9, now issues a deprecation warning on use. This property is slated for
964964
removal in 3.21. Use ``ast.Tuple.elts`` instead.
965965

966+
* :mod:`socket`:
967+
968+
* ``ALG_SET_PUBKEY``, ``ALG_OP_SIGN`` and ``ALG_OP_VERIFY`` are deprecated
969+
and slated for removal in Python 3.21. They are libkcapi's own values
970+
and were never defined by the Linux kernel, which uses the value of
971+
``ALG_SET_PUBKEY`` for ``ALG_SET_DRBG_ENTROPY``.
972+
(Contributed by Parman Mohammadalizadeh in :gh:`158285`.)
973+
966974
* :mod:`struct`:
967975

968976
* The ``'F'`` and ``'D'`` type codes, soft-deprecated since Python 3.15,

‎Lib/socket.py‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@
6666
EAGAIN = getattr(errno, 'EAGAIN', 11)
6767
EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', 11)
6868

69+
# gh-158285: libkcapi's own values, never defined by mainline Linux.
70+
_deprecated_names = {name: globals().pop(name)
71+
for name in ('ALG_SET_PUBKEY', 'ALG_OP_SIGN', 'ALG_OP_VERIFY')
72+
if name in globals()}
73+
6974
__all__ = ["fromfd", "getfqdn", "create_connection", "create_server",
7075
"has_dualstack_ipv6", "AddressFamily", "SocketKind"]
71-
__all__.extend(os._get_exports_list(_socket))
76+
__all__.extend(name for name in os._get_exports_list(_socket)
77+
if name not in _deprecated_names)
7278

7379
# Set up the socket.AF_* socket.SOCK_* constants as members of IntEnums for
7480
# nicer string representations.
@@ -1012,3 +1018,13 @@ def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
10121018
_intenum_converter(socktype, SocketKind),
10131019
proto, canonname, sa))
10141020
return addrlist
1021+
1022+
1023+
def __getattr__(name):
1024+
try:
1025+
value = _deprecated_names[name]
1026+
except KeyError:
1027+
raise AttributeError(f"module 'socket' has no attribute {name!r}") from None
1028+
import warnings
1029+
warnings._deprecated(f"socket.{name}", remove=(3, 21))
1030+
return value

‎Lib/test/test_socket.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,16 @@ def test_socket_type(self):
951951
with self.assertRaisesRegex(TypeError, "immutable"):
952952
_socket.socket.foo = 1
953953

954+
@unittest.skipUnless(hasattr(_socket, 'ALG_SET_PUBKEY'),
955+
'need the libkcapi ALG_* constants')
956+
def test_deprecated_alg_constants(self):
957+
for name in ('ALG_SET_PUBKEY', 'ALG_OP_SIGN', 'ALG_OP_VERIFY'):
958+
with self.subTest(name=name):
959+
self.assertNotIn(name, socket.__all__)
960+
with self.assertWarnsRegex(DeprecationWarning, name):
961+
value = getattr(socket, name)
962+
self.assertEqual(value, getattr(_socket, name))
963+
954964
def test_SocketType_is_socketobject(self):
955965
import _socket
956966
self.assertTrue(socket.SocketType is _socket.socket)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecate :mod:`socket` constants ``ALG_SET_PUBKEY``, ``ALG_OP_SIGN`` and
2+
``ALG_OP_VERIFY``. They are libkcapi's own values and were never defined by the
3+
Linux kernel, which uses the value of ``ALG_SET_PUBKEY`` for
4+
``ALG_SET_DRBG_ENTROPY``.

0 commit comments

Comments
 (0)