[issue10819] ValueError on repr(closed_socket_file)
Nir Soffer
report at bugs.python.org
Wed Jul 24 11:16:38 EDT 2019
Nir Soffer <nirsof at gmail.com> added the comment:
I find this new behavior a usability regression. Before this change, code
(e.g python 2 code ported to python 3) could do:
fd = sock.fileno()
Without handling errors, since closed socket would raise (good). Now such code need to check the return value (bad):
fd = sock.fileno()
if fd == -1:
fail...
This is also not consistent with other objects:
>>> f = open("Makefile")
>>> f.fileno()
3
>>> f.close()
>>> f.fileno()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file
>>> repr(f)
"<_io.TextIOWrapper name='Makefile' mode='r' encoding='UTF-8'>"
The issue with repr() on closed socket can be mitigated easily inside __repr__, handling closed sockets without affecting code using file descriptors.
Can we return the old safe behavior?
----------
nosy: +nirs
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue10819>
_______________________________________
More information about the Python-bugs-list
mailing list