Skip to content

Commit 76b0c79

Browse files
committed
avoid copying code objects for ki protected function
1 parent 49bd5c3 commit 76b0c79

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/trio/_core/_ki.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ def enable_ki_protection(f: _T_supports_code, /) -> _T_supports_code:
226226
if legacy_isasyncgenfunction(f):
227227
f = f.__wrapped__ # type: ignore
228228

229-
code = f.__code__.replace()
230-
_CODE_KI_PROTECTION_STATUS_WMAP[code] = True
231-
f.__code__ = code
229+
_CODE_KI_PROTECTION_STATUS_WMAP[f.__code__] = True
232230
return orig
233231

234232

@@ -239,9 +237,7 @@ def disable_ki_protection(f: _T_supports_code, /) -> _T_supports_code:
239237
if legacy_isasyncgenfunction(f):
240238
f = f.__wrapped__ # type: ignore
241239

242-
code = f.__code__.replace()
243-
_CODE_KI_PROTECTION_STATUS_WMAP[code] = False
244-
f.__code__ = code
240+
_CODE_KI_PROTECTION_STATUS_WMAP[f.__code__] = False
245241
return orig
246242

247243

src/trio/_core/_tests/test_ki.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,14 @@ def _identity(v: _T) -> _T:
529529
return v
530530

531531

532+
@pytest.mark.xfail(
533+
strict=True,
534+
raises=AssertionError,
535+
reason=(
536+
"it was decided not to protect against this case, see discussion in: "
537+
"https://github.com/python-trio/trio/pull/3110#discussion_r1802123644"
538+
),
539+
)
532540
async def test_ki_does_not_leak_accross_different_calls_to_inner_functions() -> None:
533541
assert not _core.currently_ki_protected()
534542

0 commit comments

Comments
 (0)