-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-45813: Drop redundant assertion from frame.clear() #29990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -686,7 +686,6 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) | |||
} | |||
if (f->f_frame->generator) { | |||
_PyGen_Finalize(f->f_frame->generator); | |||
assert(f->f_frame->generator == NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check doesn't make sense, frame->generator
consistency is checked by InterpreterFrame
(Python/frame.c), not by PyFrameObject
(Objects/frameobject.c).
@markshannon I very much appreciate it if you find time for the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. This assert would be appropriate in the dealloc
function, but not in clear
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant idea. Added assertion to frame_dealloc()
.
@@ -686,7 +686,6 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) | |||
} | |||
if (f->f_frame->generator) { | |||
_PyGen_Finalize(f->f_frame->generator); | |||
assert(f->f_frame->generator == NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant idea. Added assertion to frame_dealloc()
.
'This would crash the interpreter in 3.11a2' | ||
async def f(): | ||
pass | ||
frame = f().cr_frame | ||
frame.clear() | ||
with self.assertWarns(RuntimeWarning): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppress printing RuntimeWarning: coroutine 'CoroutineTest.test_bpo_....<locals>.f' was never awaited
on the console.
#29700 fixes one crash scenario.
This PR fixes a case when the generator is held by external reference, not the generator's frame object.
A separate NEWs entry is not required, #29700 already provides a good enough description.
https://bugs.python.org/issue45813