mirror of
https://github.com/python/cpython.git
synced 2025-09-24 17:33:29 +00:00
gh-132775: Add _PyCode_GetScriptXIData() (gh-133480)
This converts functions, code, str, bytes, bytearray, and memoryview objects to PyCodeObject, and ensure that the object looks like a script. That means no args, no return, and no closure. _PyCode_GetPureScriptXIData() takes it a step further and ensures there are no globals. We also add _PyObject_SupportedAsScript() to the internal C-API.
This commit is contained in:
parent
f0f93ba5fa
commit
c81fa2b9cd
8 changed files with 366 additions and 0 deletions
|
@ -673,6 +673,20 @@ class CodeTest(unittest.TestCase):
|
|||
VARKWARGS = CO_FAST_LOCAL | CO_FAST_ARG_VAR | CO_FAST_ARG_KW
|
||||
|
||||
funcs = {
|
||||
defs.simple_script: {},
|
||||
defs.complex_script: {
|
||||
'obj': CO_FAST_LOCAL,
|
||||
'pickle': CO_FAST_LOCAL,
|
||||
'spam_minimal': CO_FAST_LOCAL,
|
||||
'data': CO_FAST_LOCAL,
|
||||
'res': CO_FAST_LOCAL,
|
||||
},
|
||||
defs.script_with_globals: {
|
||||
'obj1': CO_FAST_LOCAL,
|
||||
'obj2': CO_FAST_LOCAL,
|
||||
},
|
||||
defs.script_with_explicit_empty_return: {},
|
||||
defs.script_with_return: {},
|
||||
defs.spam_minimal: {},
|
||||
defs.spam_with_builtins: {
|
||||
'x': CO_FAST_LOCAL,
|
||||
|
@ -898,6 +912,19 @@ class CodeTest(unittest.TestCase):
|
|||
}
|
||||
|
||||
funcs = {
|
||||
defs.simple_script: new_var_counts(),
|
||||
defs.complex_script: new_var_counts(
|
||||
purelocals=5,
|
||||
globalvars=1,
|
||||
attrs=2,
|
||||
),
|
||||
defs.script_with_globals: new_var_counts(
|
||||
purelocals=2,
|
||||
globalvars=1,
|
||||
),
|
||||
defs.script_with_explicit_empty_return: new_var_counts(),
|
||||
defs.script_with_return: new_var_counts(),
|
||||
defs.spam_minimal: new_var_counts(),
|
||||
defs.spam_minimal: new_var_counts(),
|
||||
defs.spam_with_builtins: new_var_counts(
|
||||
purelocals=4,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue