mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-132775: Revert "gh-132775: Add _PyCode_VerifyStateless() (gh-133221)" (#133497)
This commit is contained in:
parent
fd37f1a8ad
commit
3c73cf51df
8 changed files with 37 additions and 362 deletions
|
@ -220,7 +220,6 @@ try:
|
|||
import _testinternalcapi
|
||||
except ModuleNotFoundError:
|
||||
_testinternalcapi = None
|
||||
import test._code_definitions as defs
|
||||
|
||||
COPY_FREE_VARS = opmap['COPY_FREE_VARS']
|
||||
|
||||
|
@ -672,6 +671,7 @@ class CodeTest(unittest.TestCase):
|
|||
VARARGS = CO_FAST_LOCAL | CO_FAST_ARG_VAR | CO_FAST_ARG_POS
|
||||
VARKWARGS = CO_FAST_LOCAL | CO_FAST_ARG_VAR | CO_FAST_ARG_KW
|
||||
|
||||
import test._code_definitions as defs
|
||||
funcs = {
|
||||
defs.spam_minimal: {},
|
||||
defs.spam_with_builtins: {
|
||||
|
@ -897,6 +897,7 @@ class CodeTest(unittest.TestCase):
|
|||
},
|
||||
}
|
||||
|
||||
import test._code_definitions as defs
|
||||
funcs = {
|
||||
defs.spam_minimal: new_var_counts(),
|
||||
defs.spam_with_builtins: new_var_counts(
|
||||
|
@ -1024,35 +1025,42 @@ class CodeTest(unittest.TestCase):
|
|||
counts = _testinternalcapi.get_code_var_counts(func.__code__)
|
||||
self.assertEqual(counts, expected)
|
||||
|
||||
func = defs.spam_with_globals_and_builtins
|
||||
def func_with_globals_and_builtins():
|
||||
mod1 = _testinternalcapi
|
||||
mod2 = dis
|
||||
mods = (mod1, mod2)
|
||||
checks = tuple(callable(m) for m in mods)
|
||||
return callable(mod2), tuple(mods), list(mods), checks
|
||||
|
||||
func = func_with_globals_and_builtins
|
||||
with self.subTest(f'{func} code'):
|
||||
expected = new_var_counts(
|
||||
purelocals=5,
|
||||
globalvars=6,
|
||||
purelocals=4,
|
||||
globalvars=5,
|
||||
)
|
||||
counts = _testinternalcapi.get_code_var_counts(func.__code__)
|
||||
self.assertEqual(counts, expected)
|
||||
|
||||
with self.subTest(f'{func} with own globals and builtins'):
|
||||
expected = new_var_counts(
|
||||
purelocals=5,
|
||||
globalvars=(2, 4),
|
||||
purelocals=4,
|
||||
globalvars=(2, 3),
|
||||
)
|
||||
counts = _testinternalcapi.get_code_var_counts(func)
|
||||
self.assertEqual(counts, expected)
|
||||
|
||||
with self.subTest(f'{func} without globals'):
|
||||
expected = new_var_counts(
|
||||
purelocals=5,
|
||||
globalvars=(0, 4, 2),
|
||||
purelocals=4,
|
||||
globalvars=(0, 3, 2),
|
||||
)
|
||||
counts = _testinternalcapi.get_code_var_counts(func, globalsns={})
|
||||
self.assertEqual(counts, expected)
|
||||
|
||||
with self.subTest(f'{func} without both'):
|
||||
expected = new_var_counts(
|
||||
purelocals=5,
|
||||
globalvars=6,
|
||||
purelocals=4,
|
||||
globalvars=5,
|
||||
)
|
||||
counts = _testinternalcapi.get_code_var_counts(func, globalsns={},
|
||||
builtinsns={})
|
||||
|
@ -1060,34 +1068,12 @@ class CodeTest(unittest.TestCase):
|
|||
|
||||
with self.subTest(f'{func} without builtins'):
|
||||
expected = new_var_counts(
|
||||
purelocals=5,
|
||||
globalvars=(2, 0, 4),
|
||||
purelocals=4,
|
||||
globalvars=(2, 0, 3),
|
||||
)
|
||||
counts = _testinternalcapi.get_code_var_counts(func, builtinsns={})
|
||||
self.assertEqual(counts, expected)
|
||||
|
||||
@unittest.skipIf(_testinternalcapi is None, "missing _testinternalcapi")
|
||||
def test_stateless(self):
|
||||
self.maxDiff = None
|
||||
|
||||
for func in defs.STATELESS_CODE:
|
||||
with self.subTest((func, '(code)')):
|
||||
_testinternalcapi.verify_stateless_code(func.__code__)
|
||||
for func in defs.STATELESS_FUNCTIONS:
|
||||
with self.subTest((func, '(func)')):
|
||||
_testinternalcapi.verify_stateless_code(func)
|
||||
|
||||
for func in defs.FUNCTIONS:
|
||||
if func not in defs.STATELESS_CODE:
|
||||
with self.subTest((func, '(code)')):
|
||||
with self.assertRaises(Exception):
|
||||
_testinternalcapi.verify_stateless_code(func.__code__)
|
||||
|
||||
if func not in defs.STATELESS_FUNCTIONS:
|
||||
with self.subTest((func, '(func)')):
|
||||
with self.assertRaises(Exception):
|
||||
_testinternalcapi.verify_stateless_code(func)
|
||||
|
||||
|
||||
def isinterned(s):
|
||||
return s is sys.intern(('_' + s + '_')[1:-1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue