Skip to content

Commit 2c7209a

Browse files
authored
gh-114091: Reword error message for unawaitable types (#114090)
Reword error message for unawaitable types.
1 parent a26d27e commit 2c7209a

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

Lib/test/test_asyncio/test_locks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def test_lock(self):
3939

4040
with self.assertRaisesRegex(
4141
TypeError,
42-
"object Lock can't be used in 'await' expression"
42+
"'Lock' object can't be awaited"
4343
):
4444
await lock
4545

@@ -77,7 +77,7 @@ async def test_lock_by_with_statement(self):
7777
self.assertFalse(lock.locked())
7878
with self.assertRaisesRegex(
7979
TypeError,
80-
r"object \w+ can't be used in 'await' expression"
80+
r"'\w+' object can't be awaited"
8181
):
8282
with await lock:
8383
pass
@@ -941,7 +941,7 @@ async def test_semaphore(self):
941941

942942
with self.assertRaisesRegex(
943943
TypeError,
944-
"object Semaphore can't be used in 'await' expression",
944+
"'Semaphore' object can't be awaited",
945945
):
946946
await sem
947947

@@ -1270,7 +1270,7 @@ async def test_barrier(self):
12701270
self.assertIn("filling", repr(barrier))
12711271
with self.assertRaisesRegex(
12721272
TypeError,
1273-
"object Barrier can't be used in 'await' expression",
1273+
"'Barrier' object can't be awaited",
12741274
):
12751275
await barrier
12761276

Lib/test/test_asyncio/test_pep492.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def test(lock):
7777
self.assertFalse(lock.locked())
7878
with self.assertRaisesRegex(
7979
TypeError,
80-
"can't be used in 'await' expression"
80+
"can't be awaited"
8181
):
8282
with await lock:
8383
pass

Lib/test/test_coroutines.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,13 @@ def test_await_1(self):
974974

975975
async def foo():
976976
await 1
977-
with self.assertRaisesRegex(TypeError, "object int can.t.*await"):
977+
with self.assertRaisesRegex(TypeError, "'int' object can.t be awaited"):
978978
run_async(foo())
979979

980980
def test_await_2(self):
981981
async def foo():
982982
await []
983-
with self.assertRaisesRegex(TypeError, "object list can.t.*await"):
983+
with self.assertRaisesRegex(TypeError, "'list' object can.t be awaited"):
984984
run_async(foo())
985985

986986
def test_await_3(self):
@@ -1040,7 +1040,7 @@ class Awaitable:
10401040
async def foo(): return await Awaitable()
10411041

10421042
with self.assertRaisesRegex(
1043-
TypeError, "object Awaitable can't be used in 'await' expression"):
1043+
TypeError, "'Awaitable' object can't be awaited"):
10441044

10451045
run_async(foo())
10461046

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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".

Objects/genobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ _PyCoro_GetAwaitableIter(PyObject *o)
10471047
}
10481048

10491049
PyErr_Format(PyExc_TypeError,
1050-
"object %.100s can't be used in 'await' expression",
1050+
"'%.100s' object can't be awaited",
10511051
ot->tp_name);
10521052
return NULL;
10531053
}

0 commit comments

Comments
 (0)