mirror of
https://github.com/python/cpython.git
synced 2025-07-10 04:45:36 +00:00
gh-135450: Remove assertion in _PyCode_CheckNoExternalState
(gh-135466)
The assertion reflected a misunderstanding of situations where "hidden" variables might exist, namely generator expressions and comprehensions.
This commit is contained in:
parent
e9b647dd30
commit
15f2bac02c
2 changed files with 16 additions and 1 deletions
|
@ -944,6 +944,22 @@ class TestInterpreterExec(TestBase):
|
||||||
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
|
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
|
||||||
interp.exec('raise Exception("it worked!")')
|
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
|
# test__interpreters covers the remaining
|
||||||
# Interpreter.exec() behavior.
|
# Interpreter.exec() behavior.
|
||||||
|
|
||||||
|
|
|
@ -1999,7 +1999,6 @@ _PyCode_CheckNoExternalState(PyCodeObject *co, _PyCode_var_counts_t *counts,
|
||||||
const char **p_errmsg)
|
const char **p_errmsg)
|
||||||
{
|
{
|
||||||
const char *errmsg = NULL;
|
const char *errmsg = NULL;
|
||||||
assert(counts->locals.hidden.total == 0);
|
|
||||||
if (counts->numfree > 0) { // It's a closure.
|
if (counts->numfree > 0) { // It's a closure.
|
||||||
errmsg = "closures not supported";
|
errmsg = "closures not supported";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue