Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit929afd1

Browse files
sobolevnpicnixz
andauthored
gh-131670: Fix crash inanext() when__anext__ is sync and raises (#131682)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent5fef4ff commit929afd1

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

‎Lib/test/test_asyncgen.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,26 @@ async def run():
11691169

11701170
self.loop.run_until_complete(run())
11711171

1172+
deftest_sync_anext_raises_exception(self):
1173+
# See: https://github.com/python/cpython/issues/131670
1174+
msg='custom'
1175+
forexc_typein [
1176+
StopAsyncIteration,
1177+
StopIteration,
1178+
ValueError,
1179+
Exception,
1180+
]:
1181+
exc=exc_type(msg)
1182+
withself.subTest(exc=exc):
1183+
classA:
1184+
def__anext__(self):
1185+
raiseexc
1186+
1187+
withself.assertRaisesRegex(exc_type,msg):
1188+
anext(A())
1189+
withself.assertRaisesRegex(exc_type,msg):
1190+
anext(A(),1)
1191+
11721192
deftest_async_gen_asyncio_anext_stopiteration(self):
11731193
asyncdeffoo():
11741194
try:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix:func:`anext` failing on sync:meth:`~object.__anext__` raising an exception.

‎Python/bltinmodule.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,9 @@ builtin_anext_impl(PyObject *module, PyObject *aiterator,
18371837
}
18381838

18391839
awaitable= (*t->tp_as_async->am_anext)(aiterator);
1840+
if (awaitable==NULL) {
1841+
returnNULL;
1842+
}
18401843
if (default_value==NULL) {
18411844
returnawaitable;
18421845
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp