Skip to content
Draft
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
341a29e
deprecated SocketType
rruuaanng Nov 1, 2024
a4ef847
_socket.socket change to _socket.SocketType
rruuaanng Nov 1, 2024
5a57cb1
Remove return
rruuaanng Nov 1, 2024
72f7c3d
Change docs
rruuaanng Nov 1, 2024
58b305d
Change NEWS
rruuaanng Nov 1, 2024
73b14ea
Change docs
rruuaanng Nov 1, 2024
2c2e8e3
Change NEWS
rruuaanng Nov 1, 2024
3ea9169
Move import
rruuaanng Nov 1, 2024
3b7d187
Add return
rruuaanng Nov 1, 2024
188a924
socket rename to SocketType
rruuaanng Nov 2, 2024
ce4bfa6
Remove defined
rruuaanng Nov 2, 2024
362dbab
Return _socket.socket
rruuaanng Nov 2, 2024
5042f2f
Add AttributeError
rruuaanng Nov 2, 2024
4676d96
Add pending3.16
rruuaanng Nov 2, 2024
3e85bc7
warn change to _deprecated
rruuaanng Nov 2, 2024
da2aabe
Change info
rruuaanng Nov 2, 2024
0afac16
Remove ~
rruuaanng Nov 3, 2024
f2736c2
Change NEWS
rruuaanng Nov 3, 2024
2fdba78
Change pending
rruuaanng Nov 3, 2024
7f841cf
Change NEWS
rruuaanng Nov 7, 2024
36598e1
Change docs
rruuaanng Nov 7, 2024
931ce2b
Change removal
rruuaanng Nov 7, 2024
28e78d0
Add some space
rruuaanng Nov 7, 2024
aa3ab5b
Add :
rruuaanng Nov 8, 2024
45a4f34
Remove ‘in type annotations’
rruuaanng Nov 8, 2024
261d87f
Add newline(boom)
rruuaanng Nov 8, 2024
de41cb5
Add module __getattr__
rruuaanng Nov 16, 2024
e4302d0
Remove redundant test method
rruuaanng Nov 16, 2024
705492b
Restore SocketType
rruuaanng Nov 16, 2024
4752f84
Change cmod | remove getattr in socket.py
rruuaanng Nov 16, 2024
44c5ed9
Restore getattr in socket.py
rruuaanng Nov 16, 2024
f05ae78
Remove getattr in socket.py
rruuaanng Nov 17, 2024
b30dcb9
Add free
rruuaanng Nov 17, 2024
eead93e
Merge branch 'gh88427' of https://github.com/rruuaanng/cpython into g…
rruuaanng Nov 17, 2024
02a45bd
Recover __getattr__ in socket.py
rruuaanng Nov 18, 2024
936f05f
Change warn desc
rruuaanng Nov 19, 2024
377b414
Recover email
rruuaanng Nov 19, 2024
538acd0
Change warn desc
rruuaanng Nov 19, 2024
d584e6d
Change warn desc
rruuaanng Nov 19, 2024
4d71bce
Remove SocketType original definition
rruuaanng Nov 19, 2024
347c8e3
_socket.socket change to _socket.SocketType
rruuaanng Nov 19, 2024
e625c64
strcmp change to PyUnicode_EqualToUTF8
rruuaanng Nov 20, 2024
a909333
Merge branch 'gh88427' of https://github.com/rruuaanng/cpython into g…
rruuaanng Nov 20, 2024
0d836c4
Use a better implementation
rruuaanng Dec 8, 2024
38efc89
Clear CI error
rruuaanng Dec 8, 2024
e07a953
Add cast
rruuaanng Dec 8, 2024
fae620a
use _socket.SocketType
rruuaanng Dec 9, 2024
f029878
Merge branch 'main' into gh88427
rruuaanng Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/deprecations/pending-removal-in-3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Pending Removal in Python 3.16
* :mod:`builtins`:
``~bool``, bitwise inversion on bool.

* :mod:`socket`:
:class:`socket.SocketType`: use :class:`socket.socket` type instead.
(Contributed by James Roy in :gh:`88427`.)

* :mod:`symtable`:
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest.
(Contributed by Bénédikt Tran in :gh:`119698`.)
Expand Down
3 changes: 3 additions & 0 deletions Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,9 @@ The following functions all create :ref:`socket objects <socket-objects>`.
This is a Python type object that represents the socket object type. It is the
same as ``type(socket(...))``.

.. deprecated:: next
Use :class:`socket.socket` type instead.


Other functions
'''''''''''''''
Expand Down
5 changes: 5 additions & 0 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
"has_dualstack_ipv6", "AddressFamily", "SocketKind"]
__all__.extend(os._get_exports_list(_socket))

def __getattr__(name):
if name == "SocketType":
return _socket.socket
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

# Set up the socket.AF_* socket.SOCK_* constants as members of IntEnums for
# nicer string representations.
# Note that _socket only knows about the integer values. The public interface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:attr:`!socket.SocketType` is now deprecated and planned to be removed in Python 3.16. Use :class:`socket.socket` instead.
24 changes: 24 additions & 0 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5574,6 +5574,29 @@ static PyType_Spec sock_spec = {
.slots = sock_slots,
};

static PyObject *
socket_getattr(PyObject *self, PyObject *name)
{
PyObject *sock_type = PyType_FromSpec(&sock_spec);
if (sock_type == NULL) {
return NULL;
}
const char *attrname = PyUnicode_AsUTF8(name);
if (attrname == NULL) {
Py_DECREF(sock_type);
return NULL;
}

if (!strcmp(attrname, "SocketType")) {
PyErr_Warn(PyExc_DeprecationWarning, "_socket.SocketType is deprecated and will be removed in Python 3.16. "
"Use socket.socket instead");
return sock_type;
}

PyErr_Format(PyExc_AttributeError, "module _socket has no attribute '%s'", attrname);
Py_DECREF(sock_type);
return NULL;
}

#ifdef HAVE_GETHOSTNAME
/* Python interface to gethostname(). */
Expand Down Expand Up @@ -7179,6 +7202,7 @@ range of values.");
/* List of functions exported by this module. */

static PyMethodDef socket_methods[] = {
{"__getattr__", socket_getattr, METH_O, "Module __getattr__"},
#ifdef HAVE_GETADDRINFO
{"gethostbyname", socket_gethostbyname,
METH_VARARGS, gethostbyname_doc},
Expand Down
Loading