Reword error message for unawaitable types.
with self.assertRaisesRegex(
TypeError,
- "object Lock can't be used in 'await' expression"
+ "'Lock' object can't be awaited"
):
await lock
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
with self.assertRaisesRegex(
TypeError,
- "object Semaphore can't be used in 'await' expression",
+ "'Semaphore' object can't be awaited",
):
await sem
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
self.assertFalse(lock.locked())
with self.assertRaisesRegex(
TypeError,
- "can't be used in 'await' expression"
+ "can't be awaited"
):
with await lock:
pass
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):
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())
--- /dev/null
+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".
}
PyErr_Format(PyExc_TypeError,
- "object %.100s can't be used in 'await' expression",
+ "'%.100s' object can't be awaited",
ot->tp_name);
return NULL;
}