all Python 3socketterm
socket.SocketType
creating sockets
The base socket class from _socket: fine for isinstance(), but not the class that socket.socket() creates.
Syntax
isinstance(obj, socket.SocketType)
isinstance(sock, socket.SocketType) is true, yet type(sock) is socket.SocketType is false: objects are made by the subclass socket.socket. A bare SocketType instance is cut down, with no makefile() and no with support, so do not create sockets from it. Subclass and instantiate socket.socket; SocketType is only good for type checks.
Examples
import socket
with socket.socket() as s:
print(isinstance(s, socket.SocketType)) # → True
print(type(s) is socket.SocketType) # → False
print(type(s) is socket.socket) # → True
print(socket.SocketType is socket.socket) # → False
See also
Open in the full glossarydocs.python.orgReport an inaccuracy