gh-127274: Defer nested methods (#128012)

Methods (functions defined in class scope) are likely to be cleaned
up by the GC anyway.

Add a new code flag, `CO_METHOD`, that is set for functions defined
in a class scope. Use that when deciding to defer functions.
This commit is contained in:
mpage 2024-12-19 13:03:14 -08:00 committed by GitHub
parent e163e8d4e1
commit 255762c09f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 37 additions and 14 deletions

View file

@ -138,6 +138,13 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_has_docstring = 0;
ste->ste_method = 0;
if (st->st_cur != NULL &&
st->st_cur->ste_type == ClassBlock &&
block == FunctionBlock) {
ste->ste_method = 1;
}
ste->ste_symbols = PyDict_New();
ste->ste_varnames = PyList_New(0);
ste->ste_children = PyList_New(0);