Commit 58fc7970 authored by Stefan Behnel's avatar Stefan Behnel

also call coroutine finalisation for non-started instances as we need to warn about them

parent 74924b54
...@@ -1066,8 +1066,8 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) { ...@@ -1066,8 +1066,8 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) {
if (gen->gi_weakreflist != NULL) if (gen->gi_weakreflist != NULL)
PyObject_ClearWeakRefs(self); PyObject_ClearWeakRefs(self);
if (gen->resume_label > 0) { if (gen->resume_label >= 0) {
// Generator is paused, so we need to close // Generator is paused or unstarted, so we need to close
PyObject_GC_Track(self); PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1 #if PY_VERSION_HEX >= 0x030400a1
if (PyObject_CallFinalizerFromDealloc(self)) if (PyObject_CallFinalizerFromDealloc(self))
......
...@@ -977,6 +977,7 @@ class CoroutineTest(unittest.TestCase): ...@@ -977,6 +977,7 @@ class CoroutineTest(unittest.TestCase):
def test_func_9(self): def test_func_9(self):
async def foo(): pass async def foo(): pass
gc.collect()
with self.assertWarnsRegex( with self.assertWarnsRegex(
RuntimeWarning, "coroutine '.*test_func_9.*foo' was never awaited"): RuntimeWarning, "coroutine '.*test_func_9.*foo' was never awaited"):
...@@ -2386,6 +2387,8 @@ class CoroutineTest(unittest.TestCase): ...@@ -2386,6 +2387,8 @@ class CoroutineTest(unittest.TestCase):
def test_fatal_coro_warning(self): def test_fatal_coro_warning(self):
# Issue 27811 # Issue 27811
async def func(): pass async def func(): pass
gc.collect()
with warnings.catch_warnings(), captured_stderr() as stderr: with warnings.catch_warnings(), captured_stderr() as stderr:
warnings.filterwarnings("error") warnings.filterwarnings("error")
func() func()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment