Skip to content

gh-114091: Reword error message for unawaitable types #114090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lib/test/test_asyncio/test_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def test_lock(self):

with self.assertRaisesRegex(
TypeError,
"object Lock can't be used in 'await' expression"
"'Lock' object can't be awaited"
):
await lock

Expand Down Expand Up @@ -77,7 +77,7 @@ async def test_lock_by_with_statement(self):
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
Expand Down Expand Up @@ -941,7 +941,7 @@ async def test_semaphore(self):

with self.assertRaisesRegex(
TypeError,
"object Semaphore can't be used in 'await' expression",
"'Semaphore' object can't be awaited",
):
await sem

Expand Down Expand Up @@ -1270,7 +1270,7 @@ async def test_barrier(self):
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

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_pep492.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def test(lock):
self.assertFalse(lock.locked())
with self.assertRaisesRegex(
TypeError,
"can't be used in 'await' expression"
"can't be awaited"
):
with await lock:
pass
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,13 +974,13 @@ def test_await_1(self):

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):
Expand Down Expand Up @@ -1040,7 +1040,7 @@ class Awaitable:
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())

Expand Down
Original file line number Diff line number Diff line change
@@ -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".
2 changes: 1 addition & 1 deletion Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading