]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-114091: Reword error message for unawaitable types (#114090)
authorSteele Farnsworth <swfarnsworth@gmail.com>
Mon, 17 Jun 2024 14:48:17 +0000 (10:48 -0400)
committerGitHub <noreply@github.com>
Mon, 17 Jun 2024 14:48:17 +0000 (20:18 +0530)
Reword error message for unawaitable types.

Lib/test/test_asyncio/test_locks.py
Lib/test/test_asyncio/test_pep492.py
Lib/test/test_coroutines.py
Misc/NEWS.d/next/Core and Builtins/2024-01-15-21-51-26.gh-issue-114091.VOtSJl.rst [new file with mode: 0644]
Objects/genobject.c

index c961dadff9fef2c79a1d3ac8f99df5af41416b80..34509717f2872a6bdfddf75aba398504fa02218f 100644 (file)
@@ -39,7 +39,7 @@ class LockTests(unittest.IsolatedAsyncioTestCase):
 
         with self.assertRaisesRegex(
             TypeError,
-            "object Lock can't be used in 'await' expression"
+            "'Lock' object can't be awaited"
         ):
             await lock
 
@@ -77,7 +77,7 @@ class LockTests(unittest.IsolatedAsyncioTestCase):
             self.assertFalse(lock.locked())
             with self.assertRaisesRegex(
                 TypeError,
-                r"object \w+ can't be used in 'await' expression"
+                r"'\w+' object can't be awaited"
             ):
                 with await lock:
                     pass
@@ -941,7 +941,7 @@ class SemaphoreTests(unittest.IsolatedAsyncioTestCase):
 
         with self.assertRaisesRegex(
             TypeError,
-            "object Semaphore can't be used in 'await' expression",
+            "'Semaphore' object can't be awaited",
         ):
             await sem
 
@@ -1270,7 +1270,7 @@ class BarrierTests(unittest.IsolatedAsyncioTestCase):
         self.assertIn("filling", repr(barrier))
         with self.assertRaisesRegex(
             TypeError,
-            "object Barrier can't be used in 'await' expression",
+            "'Barrier' object can't be awaited",
         ):
             await barrier
 
index dc25a46985e3497e791b92099433e938f93b703c..033784bc7aec05777e7bd81a3075ae1753cc582e 100644 (file)
@@ -77,7 +77,7 @@ class LockTests(BaseTest):
             self.assertFalse(lock.locked())
             with self.assertRaisesRegex(
                 TypeError,
-                "can't be used in 'await' expression"
+                "can't be awaited"
             ):
                 with await lock:
                     pass
index f705f4f5bfbd8848502184097245da8558eb7150..a677301c62beccf7cbeae34469d23f3b76fb7fba 100644 (file)
@@ -974,13 +974,13 @@ class CoroutineTest(unittest.TestCase):
 
         async def foo():
             await 1
-        with self.assertRaisesRegex(TypeError, "object int can.t.*await"):
+        with self.assertRaisesRegex(TypeError, "'int' object can.t be awaited"):
             run_async(foo())
 
     def test_await_2(self):
         async def foo():
             await []
-        with self.assertRaisesRegex(TypeError, "object list can.t.*await"):
+        with self.assertRaisesRegex(TypeError, "'list' object can.t be awaited"):
             run_async(foo())
 
     def test_await_3(self):
@@ -1040,7 +1040,7 @@ class CoroutineTest(unittest.TestCase):
         async def foo(): return await Awaitable()
 
         with self.assertRaisesRegex(
-            TypeError, "object Awaitable can't be used in 'await' expression"):
+            TypeError, "'Awaitable' object can't be awaited"):
 
             run_async(foo())
 
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-01-15-21-51-26.gh-issue-114091.VOtSJl.rst b/Misc/NEWS.d/next/Core and Builtins/2024-01-15-21-51-26.gh-issue-114091.VOtSJl.rst
new file mode 100644 (file)
index 0000000..55b7d91
--- /dev/null
@@ -0,0 +1 @@
+Changed the error message for awaiting something that can't be awaited from "object <type> can't be used in an await expression" to "'<type>' object can't be awaited".
index 92cd8c61e7e9ca251ce66e5ef4b08a3b2e8ffb54..662e644f8aeddd25b96737cfb68be9276ef8a4cc 100644 (file)
@@ -1047,7 +1047,7 @@ _PyCoro_GetAwaitableIter(PyObject *o)
     }
 
     PyErr_Format(PyExc_TypeError,
-                 "object %.100s can't be used in 'await' expression",
+                 "'%.100s' object can't be awaited",
                  ot->tp_name);
     return NULL;
 }