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

Commit3492098

Browse files
miss-islingtonsobolevnpicnixz
authored
[3.13]gh-131670: Fix crash inanext() when__anext__ is sync and raises (GH-131682) (#131686)
gh-131670: Fix crash in `anext()` when `__anext__` is sync and raises (GH-131682)(cherry picked from commit929afd1)Co-authored-by: sobolevn <mail@sobolevn.me>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent9f36dff commit3492098

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
@@ -1737,6 +1737,9 @@ builtin_anext_impl(PyObject *module, PyObject *aiterator,
17371737
}
17381738

17391739
awaitable= (*t->tp_as_async->am_anext)(aiterator);
1740+
if (awaitable==NULL) {
1741+
returnNULL;
1742+
}
17401743
if (default_value==NULL) {
17411744
returnawaitable;
17421745
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp