summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_interpreters/test_api.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-06-18 23:57:18 (GMT)
committerGitHub <noreply@github.com>2025-06-18 23:57:18 (GMT)
commitc03f94e7fe2fe96827ed96ce78aed0fc88fb8358 (patch)
tree19473be51a2330ccd64b0877bd5df028feb6596c /Lib/test/test_interpreters/test_api.py
parent47ee2aedf11fe6fb274dfc2bfc9ac51136f6113c (diff)
downloadcpython-c03f94e7fe2fe96827ed96ce78aed0fc88fb8358.zip
cpython-c03f94e7fe2fe96827ed96ce78aed0fc88fb8358.tar.gz
cpython-c03f94e7fe2fe96827ed96ce78aed0fc88fb8358.tar.bz2
[3.14] gh-135450: Remove assertion in `_PyCode_CheckNoExternalState` (gh-135694)
The assertion reflected a misunderstanding of situations where "hidden" variables might exist, namely generator expressions and comprehensions. (cherry picked from commit 15f2bac02c5e, AKA gh-135466) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Diffstat (limited to 'Lib/test/test_interpreters/test_api.py')
-rw-r--r--Lib/test/test_interpreters/test_api.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py
index 612e824..0ee4582 100644
--- a/Lib/test/test_interpreters/test_api.py
+++ b/Lib/test/test_interpreters/test_api.py
@@ -944,6 +944,22 @@ class TestInterpreterExec(TestBase):
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.