[issue32331] apply SOCK_TYPE_MASK to socket.type on Linux
Yury Selivanov
report at bugs.python.org
Fri Dec 15 11:38:52 EST 2017
Yury Selivanov <yselivanov at gmail.com> added the comment:
On GH (https://github.com/python/cpython/pull/4877), Antoine wrote:
> I agree with Victor:
> it can't go into 3.6
> making the change in 3.7 is contentious
> Can there be an other way to solve the issue? Can we for example keep socket.type as it is and add a utility function or a property reporting the "masked" type?
I agree. Here's what I propose:
1. We don't touch `socket.type`. We don't know what kind of code exists out there and in what ways it will break. The ship has sailed to fix it.
2. We add `socket.SOCK_TYPE_MASK` (on Linux).
3. We fix `socket.__repr__` to correctly render type. Currently:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
>>> s
<socket.socket fd=3, family=AddressFamily.AF_INET, type=2049, proto=0, laddr=('0.0.0.0', 0)>
What I want to see:
<socket.socket fd=3, family=AddressFamily.AF_INET, type=SOCK_STREAM | SOCK_NONBLOCK, proto=0, laddr=('0.0.0.0', 0)>
4. We add `socket.true_type` which will apply `SOCK_TYPE_MASK` and return a socket type that's safe to compare to `socket.SOCK_*` constants.
Thoughts?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32331>
_______________________________________
More information about the Python-bugs-list
mailing list