https://github.com/python/cpython/commit/a385d204d0ec720f044cbfbbad0e4e7360f93392
commit: a385d204d0ec720f044cbfbbad0e4e7360f93392
branch: main
author: Zain Nadeem <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-06-28T15:56:27+05:30
summary:

gh-152099: Raise SendfileNotAvailableError for fallback-only transports in 
asyncio (#152223)

files:
A Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst
M Lib/asyncio/base_events.py
M Lib/test/test_asyncio/test_sendfile.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index bb736222b0b3866..93bd7df993d8270 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1283,7 +1283,7 @@ async def sendfile(self, transport, file, offset=0, 
count=None,
                     raise
 
         if not fallback:
-            raise RuntimeError(
+            raise exceptions.SendfileNotAvailableError(
                 f"fallback is disabled and native sendfile is not "
                 f"supported for transport {transport!r}")
         return await self._sendfile_fallback(transport, file,
diff --git a/Lib/test/test_asyncio/test_sendfile.py 
b/Lib/test/test_asyncio/test_sendfile.py
index 2d5c06f82b3ddf1..69ac9a367f6be02 100644
--- a/Lib/test/test_asyncio/test_sendfile.py
+++ b/Lib/test/test_asyncio/test_sendfile.py
@@ -580,7 +580,8 @@ def test_sendfile_no_fallback_for_fallback_transport(self):
         transport = mock.Mock()
         transport.is_closing.side_effect = lambda: False
         transport._sendfile_compatible = constants._SendfileMode.FALLBACK
-        with self.assertRaisesRegex(RuntimeError, 'fallback is disabled'):
+        with self.assertRaisesRegex(asyncio.SendfileNotAvailableError,
+                                    'fallback is disabled'):
             self.loop.run_until_complete(
                 self.loop.sendfile(transport, None, fallback=False))
 
diff --git 
a/Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst 
b/Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst
new file mode 100644
index 000000000000000..05e760bcf6ed6d3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst
@@ -0,0 +1,4 @@
+``asyncio``'s ``loop.sendfile(..., fallback=False)`` now consistently raises
+:exc:`asyncio.SendfileNotAvailableError` for fallback-only transports, such as
+SSL/TLS transports, when native sendfile cannot be used. Previously, this case
+raised :exc:`RuntimeError`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to