]> granicus.if.org Git - python/commitdiff
bpo-32415: Fix "error is already set" (#4999)
authorYury Selivanov <yury@magic.io>
Sat, 23 Dec 2017 21:29:26 +0000 (16:29 -0500)
committerGitHub <noreply@github.com>
Sat, 23 Dec 2017 21:29:26 +0000 (16:29 -0500)
Lib/test/test_asyncio/test_tasks.py
Modules/_asynciomodule.c

index 7bb43058c8052904b72dd16fad9f4334040594af..4cf694fe7e9779e7f767233ecb565622c3fab15f 100644 (file)
@@ -2302,6 +2302,32 @@ class PyTask_PyFuture_SubclassTests(BaseTaskTests, test_utils.TestCase):
         pass
 
 
+@unittest.skipUnless(hasattr(tasks, '_CTask'),
+                     'requires the C _asyncio module')
+class CTask_Future_Tests(test_utils.TestCase):
+
+    def test_foobar(self):
+        class Fut(asyncio.Future):
+            @property
+            def get_loop(self):
+                raise AttributeError
+
+        async def coro():
+            await fut
+            return 'spam'
+
+        self.loop = asyncio.new_event_loop()
+        try:
+            fut = Fut(loop=self.loop)
+            self.loop.call_later(0.1, fut.set_result(1))
+            task = asyncio.Task(coro(), loop=self.loop)
+            res = self.loop.run_until_complete(task)
+        finally:
+            self.loop.close()
+
+        self.assertEqual(res, 'spam')
+
+
 class BaseTaskIntrospectionTests:
     _register_task = None
     _unregister_task = None
index d626127699a2b5da100cf1f807901127632ab3f9..f70e3457c379a9313266373b62567c06db7337bf 100644 (file)
@@ -203,6 +203,7 @@ get_future_loop(PyObject *fut)
         return res;
     }
 
+    PyErr_Clear();
     return _PyObject_GetAttrId(fut, &PyId__loop);
 }