Author: Manuel Jacob <m...@manueljacob.de> Branch: py3.6 Changeset: r94002:c386ba74c681 Date: 2018-03-19 16:00 +0100 http://bitbucket.org/pypy/pypy/changeset/c386ba74c681/
Log: Change socket.close() to raise OSError if closing the underlying socket fails and remove app-level test checking the old behavior. This is a port of CPython commit 50ab1a3694c43b9ab6798b98d9e5983c78cb17e2: "Issue #26685: Raise OSError if closing a socket fails" diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py --- a/pypy/module/_socket/interp_socket.py +++ b/pypy/module/_socket/interp_socket.py @@ -292,9 +292,8 @@ """ try: self.sock.close() - except SocketError: - # cpython doesn't return any errors on close - pass + except SocketError as e: + raise converted_error(space, e) self.may_unregister_rpython_finalizer(space) def connect_w(self, space, w_addr): diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py --- a/pypy/module/_socket/test/test_sock_app.py +++ b/pypy/module/_socket/test/test_sock_app.py @@ -395,13 +395,12 @@ if os.name != 'nt': raises(OSError, os.close, fileno) - def test_socket_close_error(self): - import _socket, os - if os.name == 'nt': - skip("Windows sockets are not files") + def test_socket_close_exception(self): + import errno, _socket s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0) - os.close(s.fileno()) - s.close() + _socket.socket(fileno=s.fileno()).close() + e = raises(OSError, s.close) + assert e.value.errno in (errno.EBADF, errno.ENOTSOCK) def test_socket_connect(self): import _socket, os _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit