Skip to content

Commit 5bdf10f

Browse files
s-t-e-v-e-n-kionelmc
authored andcommitted
Support new await TypeError messages
Python 3.15 changed the TypeError exception messages that are raised if you pass in the wrong object. Handle both pre-3.15 and 3.15 and on.
1 parent a5f0403 commit 5bdf10f

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎tests/test_async_py3.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,11 @@ def __await__(self):
542542
async def foo():
543543
return await lop.Proxy(Awaitable)
544544

545-
with pytest.raises(TypeError, match='__await__.*returned non-iterator of type'):
545+
msg = '__await__.*returned non-iterator of type'
546+
if sys.version_info[:2] >= (3, 15):
547+
msg = r'__await__\(\) must return an iterator, not NoneType'
548+
549+
with pytest.raises(TypeError, match=msg):
546550
run_async(lop.Proxy(foo))
547551

548552

@@ -650,7 +654,11 @@ def __await__(self):
650654
async def foo():
651655
return await lop.Proxy(Awaitable)
652656

653-
with pytest.raises(TypeError, match=r'__await__\(\) returned a coroutine'):
657+
msg = r'__await__\(\) returned a coroutine'
658+
if sys.version_info[:2] >= (3, 15):
659+
msg = r'__await__\(\) must return an iterator, not coroutine'
660+
661+
with pytest.raises(TypeError, match=msg):
654662
run_async(lop.Proxy(foo))
655663

656664
c.close()
@@ -664,7 +672,11 @@ def __await__(self):
664672
async def foo():
665673
return await lop.Proxy(Awaitable)
666674

667-
with pytest.raises(TypeError, match='__await__.*returned non-iterator of type'):
675+
msg = '__await__.*returned non-iterator of type'
676+
if sys.version_info[:2] >= (3, 15):
677+
msg = r'__await__\(\) must return an iterator, not.*Awaitable'
678+
679+
with pytest.raises(TypeError, match=msg):
668680
run_async(lop.Proxy(foo))
669681

670682

0 commit comments

Comments
 (0)