Skip to content

Commit 4752f84

Browse files
committed
Change cmod | remove getattr in socket.py
1 parent 705492b commit 4752f84

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Lib/socket.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@
6767
"has_dualstack_ipv6", "AddressFamily", "SocketKind"]
6868
__all__.extend(os._get_exports_list(_socket))
6969

70-
def __getattr__(name):
71-
if name == "SocketType":
72-
import warnings
73-
warnings._deprecated(name, remove=(3, 16))
74-
return _socket.socket
75-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
76-
7770

7871
# Set up the socket.AF_* socket.SOCK_* constants as members of IntEnums for
7972
# nicer string representations.

Modules/socketmodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5579,16 +5579,17 @@ socket_getattr(PyObject *self, PyObject *name)
55795579
{
55805580
const char *attrname = PyUnicode_AsUTF8(name);
55815581
PyObject *sock_type = PyType_FromSpec(&sock_spec);
5582-
if (sock_type == NULL) {
5582+
if (attrname == NULL || sock_type == NULL) {
55835583
return NULL;
55845584
}
55855585

55865586
if (!strcmp(attrname, "SocketType")) {
5587-
PyErr_Warn(PyExc_DeprecationWarning, "Use socket.socket type instead");
5587+
PyErr_Warn(PyExc_DeprecationWarning, "It will be removed in 3.16. "
5588+
"Use socket.socket type instead");
55885589
return sock_type;
55895590
}
55905591

5591-
PyErr_Format(PyExc_AttributeError, "module _socket has no attribute %s", attrname);
5592+
PyErr_Format(PyExc_AttributeError, "module _socket has no attribute '%s'", attrname);
55925593
return NULL;
55935594
}
55945595

0 commit comments

Comments
 (0)