Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,22 @@ def test_created_with_capi(self):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
interp.exec('raise Exception("it worked!")')

def test_list_comprehension(self):
# gh-135450: List comprehensions caused an assertion failure
# in _PyCode_CheckNoExternalState()
import string
r_interp, w_interp = self.pipe()

interp = interpreters.create()
interp.exec(f"""if True:
import os
comp = [str(i) for i in range(10)]
os.write({w_interp}, ''.join(comp).encode())
""")
self.assertEqual(os.read(r_interp, 10).decode(), string.digits)
interp.close()


# test__interpreters covers the remaining
# Interpreter.exec() behavior.

Expand Down
1 change: 0 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,6 @@ _PyCode_CheckNoExternalState(PyCodeObject *co, _PyCode_var_counts_t *counts,
const char **p_errmsg)
{
const char *errmsg = NULL;
assert(counts->locals.hidden.total == 0);
if (counts->numfree > 0) { // It's a closure.
errmsg = "closures not supported";
}
Expand Down
Loading