Skip to content

Commit 03c8ddd

Browse files
authored
bpo-42413: socket.timeout is now an alias of TimeoutError (pythonGH-23413)
Signed-off-by: Christian Heimes <[email protected]>
1 parent 7ddbaa7 commit 03c8ddd

24 files changed

+72
-62
lines changed

Doc/library/smtplib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
3232
than a success code, an :exc:`SMTPConnectError` is raised. The optional
3333
*timeout* parameter specifies a timeout in seconds for blocking operations
3434
like the connection attempt (if not specified, the global default timeout
35-
setting will be used). If the timeout expires, :exc:`socket.timeout` is
35+
setting will be used). If the timeout expires, :exc:`TimeoutError` is
3636
raised. The optional source_address parameter allows binding
3737
to some specific source address in a machine with multiple network
3838
interfaces, and/or to some specific source TCP port. It takes a 2-tuple

Doc/library/socket.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ Exceptions
283283

284284
.. exception:: timeout
285285

286+
A deprecated alias of :exc:`TimeoutError`.
287+
286288
A subclass of :exc:`OSError`, this exception is raised when a timeout
287289
occurs on a socket which has had timeouts enabled via a prior call to
288290
:meth:`~socket.settimeout` (or implicitly through
@@ -292,6 +294,9 @@ Exceptions
292294
.. versionchanged:: 3.3
293295
This class was made a subclass of :exc:`OSError`.
294296

297+
.. versionchanged:: 3.10
298+
This class was made an alias of :exc:`TimeoutError`.
299+
295300

296301
Constants
297302
^^^^^^^^^
@@ -1208,7 +1213,7 @@ to sockets.
12081213
address family --- see above.)
12091214

12101215
If the connection is interrupted by a signal, the method waits until the
1211-
connection completes, or raise a :exc:`socket.timeout` on timeout, if the
1216+
connection completes, or raise a :exc:`TimeoutError` on timeout, if the
12121217
signal handler doesn't raise an exception and the socket is blocking or has
12131218
a timeout. For non-blocking sockets, the method raises an
12141219
:exc:`InterruptedError` exception if the connection is interrupted by a

Doc/whatsnew/3.10.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ site
263263
When a module does not define ``__loader__``, fall back to ``__spec__.loader``.
264264
(Contributed by Brett Cannon in :issue:`42133`.)
265265

266+
socket
267+
------
268+
269+
The exception :exc:`socket.timeout` is now an alias of :exc:`TimeoutError`.
270+
(Contributed by Christian Heimes in :issue:`42413`.)
271+
266272
sys
267273
---
268274

Lib/http/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def handle_one_request(self):
414414
method = getattr(self, mname)
415415
method()
416416
self.wfile.flush() #actually send the response if not already done.
417-
except socket.timeout as e:
417+
except TimeoutError as e:
418418
#a read or a write timed out. Discard this connection
419419
self.log_error("Request timed out: %r", e)
420420
self.close_connection = True

Lib/idlelib/pyshell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def start_subprocess(self):
463463
self.rpcclt.listening_sock.settimeout(10)
464464
try:
465465
self.rpcclt.accept()
466-
except socket.timeout:
466+
except TimeoutError:
467467
self.display_no_subprocess_error()
468468
return None
469469
self.rpcclt.register("console", self.tkconsole)
@@ -498,7 +498,7 @@ def restart_subprocess(self, with_cwd=False, filename=''):
498498
self.spawn_subprocess()
499499
try:
500500
self.rpcclt.accept()
501-
except socket.timeout:
501+
except TimeoutError:
502502
self.display_no_subprocess_error()
503503
return None
504504
self.transfer_path(with_cwd=with_cwd)

Lib/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def _sendfile_use_sendfile(self, file, offset=0, count=None):
377377
try:
378378
while True:
379379
if timeout and not selector_select(timeout):
380-
raise _socket.timeout('timed out')
380+
raise TimeoutError('timed out')
381381
if count:
382382
blocksize = count - total_sent
383383
if blocksize <= 0:

Lib/test/support/socket_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def transient_internet(resource_name, *, timeout=_NOT_SET, errnos=()):
225225

226226
def filter_error(err):
227227
n = getattr(err, 'errno', None)
228-
if (isinstance(err, socket.timeout) or
228+
if (isinstance(err, TimeoutError) or
229229
(isinstance(err, socket.gaierror) and n in gai_errnos) or
230230
(isinstance(err, urllib.error.HTTPError) and
231231
500 <= err.code <= 599) or

Lib/test/test_asyncio/functional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _run(self):
248248
conn, addr = self._sock.accept()
249249
except BlockingIOError:
250250
continue
251-
except socket.timeout:
251+
except TimeoutError:
252252
if not self._active:
253253
return
254254
else:

Lib/test/test_asyncore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def capture_server(evt, buf, serv):
6969
try:
7070
serv.listen()
7171
conn, addr = serv.accept()
72-
except socket.timeout:
72+
except TimeoutError:
7373
pass
7474
else:
7575
n = 200

Lib/test/test_exception_hierarchy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def test_builtin_errors(self):
4040
self.assertIs(EnvironmentError, OSError)
4141

4242
def test_socket_errors(self):
43-
self.assertIs(socket.error, IOError)
43+
self.assertIs(socket.error, OSError)
4444
self.assertIs(socket.gaierror.__base__, OSError)
4545
self.assertIs(socket.herror.__base__, OSError)
46-
self.assertIs(socket.timeout.__base__, OSError)
46+
self.assertIs(socket.timeout, TimeoutError)
4747

4848
def test_select_error(self):
4949
self.assertIs(select.error, OSError)

0 commit comments

Comments
 (0)