You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation for Python 2 and 3, socket.SocketType is defined as:
This is a Python type object that represents the socket object type. It is the same as “type(socket(...))”.
In Python 2 it is a standalone “socket._socketobject” class, which holds a “_socket.socket” instance as an internal “_sock” attribute. So the documentation and implementation are consistent. But since revision 8e062e572ea4, Python 3 no longer defines SocketType directly, and just imports the “_socket.SocketType” definition, which is an alias of “_socket.socket”. The change also defines “socket.socket” as a subclass of this low-level class. The result is that SocketType is not the exact type, but only a base class:
>>> s = socket.socket()
>>> type(s)
<class 'socket.socket' at 0x2347d48>
>>> SocketType
<class '_socket.socket' at 0x7ff9e2522280>
>>> type(s) is SocketType # Should be true according to documentation
False
>>> isinstance(s, SocketType)
True
Should the documentation just be amended, or should SocketType be changed? If SocketType is not changed, perhaps we should document that socket.socket() is a class, not just a function, and maybe deprecate SocketType.
In the previous commit, the SocketType was changed to the base class for the Socket object type. I created a PR to update the SocketType documentation. Please correct me if there is a different opinion.
Activity
vadmium commentedon Jun 24, 2016
In the documentation for Python 2 and 3, socket.SocketType is defined as:
This is a Python type object that represents the socket object type. It is the same as “type(socket(...))”.
In Python 2 it is a standalone “socket._socketobject” class, which holds a “_socket.socket” instance as an internal “_sock” attribute. So the documentation and implementation are consistent. But since revision 8e062e572ea4, Python 3 no longer defines SocketType directly, and just imports the “_socket.SocketType” definition, which is an alias of “_socket.socket”. The change also defines “socket.socket” as a subclass of this low-level class. The result is that SocketType is not the exact type, but only a base class:
Should the documentation just be amended, or should SocketType be changed? If SocketType is not changed, perhaps we should document that socket.socket() is a class, not just a function, and maybe deprecate SocketType.
shihai1991 commentedon Jul 11, 2019
In order to keep back compatible, I would prefer to update SocketType ;)
shihai1991 commentedon Aug 6, 2019
ping
iritkatriel commentedon May 19, 2022
I don't think backwards compatibility with python 2 matters anymore. A doc fix should do.
[-]SocketType changed in Python 3[/-][+][doc] SocketType changed in Python 3[/+]shihai1991 commentedon May 26, 2022
Agree. I closed #14710.
pythongh-71566: Fix SocketType introduction in the socket documentation.
xiaochen7 commentedon May 27, 2022
In the previous commit, the SocketType was changed to the base class for the Socket object type. I created a PR to update the SocketType documentation. Please correct me if there is a different opinion.
aisk commentedon Sep 6, 2026
This was covered by #150683.