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

@ -850,12 +850,6 @@ class ReturnRecorder:
def __call__(self, code, offset, val):
self.events.append(("return", code.co_name, val))
# gh-127274: CALL_ALLOC_AND_ENTER_INIT will only cache __init__ methods that
# are deferred. We only defer functions defined at the top-level.
class ValueErrorRaiser:
def __init__(self):
raise ValueError()
class ExceptionMonitoringTest(CheckEvents):
@ -1054,6 +1048,9 @@ class ExceptionMonitoringTest(CheckEvents):
@requires_specialization_ft
def test_no_unwind_for_shim_frame(self):
class ValueErrorRaiser:
def __init__(self):
raise ValueError()
def f():
try: