Author martin.panter
Recipients martin.panter
Date 2016-06-24.03:19:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1466738397.82.0.0999219877747.issue27379@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-06-24 03:19:57martin.pantersetrecipients: + martin.panter
2016-06-24 03:19:57martin.pantersetmessageid: <1466738397.82.0.0999219877747.issue27379@psf.upfronthosting.co.za>
2016-06-24 03:19:57martin.panterlinkissue27379 messages
2016-06-24 03:19:56martin.pantercreate