Skip to content

Commit 49ffaea

Browse files
Fix a crash when inline comprehension has the same local variable
as outside scope
1 parent 2542256 commit 49ffaea

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Objects/frameobject.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ framelocalsproxy_getval(_PyInterpreterFrame *frame, PyCodeObject *co, int i)
4545
if (kind == CO_FAST_FREE || kind & CO_FAST_CELL) {
4646
// The cell was set when the frame was created from
4747
// the function's closure.
48-
assert(PyCell_Check(value));
49-
cell = value;
48+
// GH-128396: With PEP 709, it's possible to have a fast variable in
49+
// an inlined comprehension that has the same name as the cell variable
50+
// in the frame, where the `kind` obtained from frame can not guarantee
51+
// that the variable is a cell.
52+
// If the variable is not a cell, we are okay with it and we can simply
53+
// return the value.
54+
if (PyCell_Check(value)) {
55+
cell = value;
56+
}
5057
}
5158

5259
if (cell != NULL) {

0 commit comments

Comments
 (0)