This caused me a lot of headaches (broken test) before figuring out what the heck was wrong: =)
>>> import socket
>>> s = socket.socket()
>>> s.type
<SocketKind.SOCK_STREAM: 1>
>>> s.setblocking(0)
>>> s.type
2049
>>> s.setblocking(1)
>>> s.type
<SocketKind.SOCK_STREAM: 1>
getsockopt() on the other hand always tells the truth:
>>> s.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
1
...so I suppose we can do that in the "type" property of the Python socket class.
It appears the type is set in socket init:
https://github.com/python/cpython/blob/1e2147b9d75a64df370a9393c2b5b9d170dc0afd/Modules/socketmodule.c#L904
...and it's changed later in setblocking:
https://github.com/python/cpython/blob/1e2147b9d75a64df370a9393c2b5b9d170dc0afd/Modules/socketmodule.c#L609 |