[issue28134] socket.socket(fileno=fd) does not work as documented

Christian Heimes report at bugs.python.org
Wed Sep 14 04:09:53 EDT 2016


Christian Heimes added the comment:

Martin, the documentation says "If fileno is specified, the other arguments are ignored, causing the socket with the specified file descriptor to return." It's a direct quote from Python 3's socket library documentation. For a non-native speaker like me, this sentence implies that socket.socket(fileno) not only ignores the arguments (which it does not) but that the constructor uses the fileno to set family, type and proto.

The socket module uses self->sock_family in several places to calculate the addr len or when it handles arguments and address information. Just look at this simple example:

>>> import socket
>>> uds = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> s = socket.socket(fileno=uds.fileno())
>>> s.bind('/tmp/sock')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: getsockaddrarg: AF_INET address must be tuple, not str
>>> uds.bind('/tmp/sock')

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28134>
_______________________________________


More information about the Python-bugs-list mailing list