Skip to content

Commit 719ccbc

Browse files
author
Yury Selivanov
authored
bpo-32415: Fix "error is already set" (#4999)
1 parent a330f48 commit 719ccbc

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lib/test/test_asyncio/test_tasks.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,32 @@ class Future(futures._PyFuture):
23022302
pass
23032303

23042304

2305+
@unittest.skipUnless(hasattr(tasks, '_CTask'),
2306+
'requires the C _asyncio module')
2307+
class CTask_Future_Tests(test_utils.TestCase):
2308+
2309+
def test_foobar(self):
2310+
class Fut(asyncio.Future):
2311+
@property
2312+
def get_loop(self):
2313+
raise AttributeError
2314+
2315+
async def coro():
2316+
await fut
2317+
return 'spam'
2318+
2319+
self.loop = asyncio.new_event_loop()
2320+
try:
2321+
fut = Fut(loop=self.loop)
2322+
self.loop.call_later(0.1, fut.set_result(1))
2323+
task = asyncio.Task(coro(), loop=self.loop)
2324+
res = self.loop.run_until_complete(task)
2325+
finally:
2326+
self.loop.close()
2327+
2328+
self.assertEqual(res, 'spam')
2329+
2330+
23052331
class BaseTaskIntrospectionTests:
23062332
_register_task = None
23072333
_unregister_task = None

Modules/_asynciomodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ get_future_loop(PyObject *fut)
203203
return res;
204204
}
205205

206+
PyErr_Clear();
206207
return _PyObject_GetAttrId(fut, &PyId__loop);
207208
}
208209

0 commit comments

Comments
 (0)