Skip to content

Commit

Permalink
pythongh-114091: Reword error message for unawaitable types (python#1…
Browse files Browse the repository at this point in the history
…14090)

Reword error message for unawaitable types.
  • Loading branch information
swfarnsworth authored Jun 17, 2024
1 parent a26d27e commit 2c7209a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
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

0 comments on commit 2c7209a

Please sign in to comment.