Blame SOURCES/python3.13-PR-3005.patch

7825d3
From d2d3d4dcdc2182e8e126c73473108eeb50eb25e7 Mon Sep 17 00:00:00 2001
7825d3
From: EXPLOSION <git@helvetica.moe>
7825d3
Date: Mon, 27 May 2024 12:23:31 +0200
7825d3
Subject: [PATCH] Fixes for 3.13
7825d3
7825d3
---
7825d3
 trio/_core/_generated_instrumentation.py |  5 +++--
7825d3
 trio/_core/_generated_io_epoll.py        |  6 +++---
7825d3
 trio/_core/_generated_io_kqueue.py       | 12 ++++++------
7825d3
 trio/_core/_generated_io_windows.py      | 18 +++++++++---------
7825d3
 trio/_core/_generated_run.py             | 17 +++++++++--------
7825d3
 trio/_core/_ki.py                        |  2 +-
7825d3
 trio/_core/_run.py                       |  6 +++---
7825d3
 trio/_tests/test_path.py                 |  2 +-
7825d3
 8 files changed, 35 insertions(+), 33 deletions(-)
7825d3
7825d3
diff --git a/trio/_core/_generated_instrumentation.py b/trio/_core/_generated_instrumentation.py
7825d3
index c7fefc3..990c405 100644
7825d3
--- a/trio/_core/_generated_instrumentation.py
7825d3
+++ b/trio/_core/_generated_instrumentation.py
7825d3
@@ -3,6 +3,7 @@
7825d3
 # *************************************************************
7825d3
 from __future__ import annotations
7825d3
 
7825d3
+import sys
7825d3
 from ._instrumentation import Instrument
7825d3
 from ._ki import LOCALS_KEY_KI_PROTECTION_ENABLED
7825d3
 from ._run import GLOBAL_RUN_CONTEXT
7825d3
@@ -17,7 +18,7 @@ def add_instrument(instrument: Instrument) -> None:
7825d3
     If ``instrument`` is already active, does nothing.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.instruments.add_instrument(instrument)
7825d3
     except AttributeError:
7825d3
@@ -37,7 +38,7 @@ def remove_instrument(instrument: Instrument) -> None:
7825d3
           deactivated.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.instruments.remove_instrument(instrument)
7825d3
     except AttributeError:
7825d3
diff --git a/trio/_core/_generated_io_epoll.py b/trio/_core/_generated_io_epoll.py
7825d3
index f80e988..7927f79 100644
7825d3
--- a/trio/_core/_generated_io_epoll.py
7825d3
+++ b/trio/_core/_generated_io_epoll.py
7825d3
@@ -16,7 +16,7 @@ assert not TYPE_CHECKING or sys.platform == "linux"
7825d3
 
7825d3
 
7825d3
 async def wait_readable(fd: (int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_readable(fd)
7825d3
     except AttributeError:
7825d3
@@ -24,7 +24,7 @@ async def wait_readable(fd: (int | _HasFileNo)) -> None:
7825d3
 
7825d3
 
7825d3
 async def wait_writable(fd: (int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_writable(fd)
7825d3
     except AttributeError:
7825d3
@@ -32,7 +32,7 @@ async def wait_writable(fd: (int | _HasFileNo)) -> None:
7825d3
 
7825d3
 
7825d3
 def notify_closing(fd: (int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.notify_closing(fd)
7825d3
     except AttributeError:
7825d3
diff --git a/trio/_core/_generated_io_kqueue.py b/trio/_core/_generated_io_kqueue.py
7825d3
index b572831..1dd0626 100644
7825d3
--- a/trio/_core/_generated_io_kqueue.py
7825d3
+++ b/trio/_core/_generated_io_kqueue.py
7825d3
@@ -20,7 +20,7 @@ assert not TYPE_CHECKING or sys.platform == "darwin"
7825d3
 
7825d3
 
7825d3
 def current_kqueue() -> select.kqueue:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.current_kqueue()
7825d3
     except AttributeError:
7825d3
@@ -30,7 +30,7 @@ def current_kqueue() -> select.kqueue:
7825d3
 def monitor_kevent(
7825d3
     ident: int, filter: int
7825d3
 ) -> ContextManager[_core.UnboundedQueue[select.kevent]]:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.monitor_kevent(ident, filter)
7825d3
     except AttributeError:
7825d3
@@ -40,7 +40,7 @@ def monitor_kevent(
7825d3
 async def wait_kevent(
7825d3
     ident: int, filter: int, abort_func: Callable[[RaiseCancelT], Abort]
7825d3
 ) -> Abort:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_kevent(
7825d3
             ident, filter, abort_func
7825d3
@@ -50,7 +50,7 @@ async def wait_kevent(
7825d3
 
7825d3
 
7825d3
 async def wait_readable(fd: (int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_readable(fd)
7825d3
     except AttributeError:
7825d3
@@ -58,7 +58,7 @@ async def wait_readable(fd: (int | _HasFileNo)) -> None:
7825d3
 
7825d3
 
7825d3
 async def wait_writable(fd: (int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_writable(fd)
7825d3
     except AttributeError:
7825d3
@@ -66,7 +66,7 @@ async def wait_writable(fd: (int | _HasFileNo)) -> None:
7825d3
 
7825d3
 
7825d3
 def notify_closing(fd: (int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.notify_closing(fd)
7825d3
     except AttributeError:
7825d3
diff --git a/trio/_core/_generated_io_windows.py b/trio/_core/_generated_io_windows.py
7825d3
index e859829..f0bef74 100644
7825d3
--- a/trio/_core/_generated_io_windows.py
7825d3
+++ b/trio/_core/_generated_io_windows.py
7825d3
@@ -20,7 +20,7 @@ assert not TYPE_CHECKING or sys.platform == "win32"
7825d3
 
7825d3
 
7825d3
 async def wait_readable(sock: (_HasFileNo | int)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_readable(sock)
7825d3
     except AttributeError:
7825d3
@@ -28,7 +28,7 @@ async def wait_readable(sock: (_HasFileNo | int)) -> None:
7825d3
 
7825d3
 
7825d3
 async def wait_writable(sock: (_HasFileNo | int)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_writable(sock)
7825d3
     except AttributeError:
7825d3
@@ -36,7 +36,7 @@ async def wait_writable(sock: (_HasFileNo | int)) -> None:
7825d3
 
7825d3
 
7825d3
 def notify_closing(handle: (Handle | int | _HasFileNo)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.notify_closing(handle)
7825d3
     except AttributeError:
7825d3
@@ -44,7 +44,7 @@ def notify_closing(handle: (Handle | int | _HasFileNo)) -> None:
7825d3
 
7825d3
 
7825d3
 def register_with_iocp(handle: (int | CData)) -> None:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.register_with_iocp(handle)
7825d3
     except AttributeError:
7825d3
@@ -54,7 +54,7 @@ def register_with_iocp(handle: (int | CData)) -> None:
7825d3
 async def wait_overlapped(
7825d3
     handle_: (int | CData), lpOverlapped: (CData | int)
7825d3
 ) -> object:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.wait_overlapped(
7825d3
             handle_, lpOverlapped
7825d3
@@ -66,7 +66,7 @@ async def wait_overlapped(
7825d3
 async def write_overlapped(
7825d3
     handle: (int | CData), data: Buffer, file_offset: int = 0
7825d3
 ) -> int:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.write_overlapped(
7825d3
             handle, data, file_offset
7825d3
@@ -78,7 +78,7 @@ async def write_overlapped(
7825d3
 async def readinto_overlapped(
7825d3
     handle: (int | CData), buffer: Buffer, file_offset: int = 0
7825d3
 ) -> int:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.io_manager.readinto_overlapped(
7825d3
             handle, buffer, file_offset
7825d3
@@ -88,7 +88,7 @@ async def readinto_overlapped(
7825d3
 
7825d3
 
7825d3
 def current_iocp() -> int:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.current_iocp()
7825d3
     except AttributeError:
7825d3
@@ -96,7 +96,7 @@ def current_iocp() -> int:
7825d3
 
7825d3
 
7825d3
 def monitor_completion_key() -> ContextManager[tuple[int, UnboundedQueue[object]]]:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.io_manager.monitor_completion_key()
7825d3
     except AttributeError:
7825d3
diff --git a/trio/_core/_generated_run.py b/trio/_core/_generated_run.py
7825d3
index 399e1db..6bfc5f2 100644
7825d3
--- a/trio/_core/_generated_run.py
7825d3
+++ b/trio/_core/_generated_run.py
7825d3
@@ -3,6 +3,7 @@
7825d3
 # *************************************************************
7825d3
 from __future__ import annotations
7825d3
 
7825d3
+import sys
7825d3
 import contextvars
7825d3
 from collections.abc import Awaitable, Callable
7825d3
 from typing import Any
7825d3
@@ -38,7 +39,7 @@ def current_statistics() -> RunStatistics:
7825d3
       other attributes vary between backends.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.current_statistics()
7825d3
     except AttributeError:
7825d3
@@ -55,7 +56,7 @@ def current_time() -> float:
7825d3
         RuntimeError: if not inside a call to :func:`trio.run`.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.current_time()
7825d3
     except AttributeError:
7825d3
@@ -64,7 +65,7 @@ def current_time() -> float:
7825d3
 
7825d3
 def current_clock() -> Clock:
7825d3
     """Returns the current :class:`~trio.abc.Clock`."""
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.current_clock()
7825d3
     except AttributeError:
7825d3
@@ -77,7 +78,7 @@ def current_root_task() -> Task | None:
7825d3
     This is the task that is the ultimate parent of all other tasks.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.current_root_task()
7825d3
     except AttributeError:
7825d3
@@ -102,7 +103,7 @@ def reschedule(task: Task, next_send: Outcome[Any] = _NO_SEND) -> None:
7825d3
           raise) from :func:`wait_task_rescheduled`.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.reschedule(task, next_send)
7825d3
     except AttributeError:
7825d3
@@ -166,7 +167,7 @@ def spawn_system_task(
7825d3
       Task: the newly spawned task
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.spawn_system_task(
7825d3
             async_fn, *args, name=name, context=context
7825d3
@@ -180,7 +181,7 @@ def current_trio_token() -> TrioToken:
7825d3
     :func:`trio.run`.
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return GLOBAL_RUN_CONTEXT.runner.current_trio_token()
7825d3
     except AttributeError:
7825d3
@@ -245,7 +246,7 @@ async def wait_all_tasks_blocked(cushion: float = 0.0) -> None:
7825d3
                      print("FAIL")
7825d3
 
7825d3
     """
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     try:
7825d3
         return await GLOBAL_RUN_CONTEXT.runner.wait_all_tasks_blocked(cushion)
7825d3
     except AttributeError:
7825d3
diff --git a/trio/_core/_ki.py b/trio/_core/_ki.py
7825d3
index 0ea3461..a5e32d5 100644
7825d3
--- a/trio/_core/_ki.py
7825d3
+++ b/trio/_core/_ki.py
7825d3
@@ -176,7 +176,7 @@ def _ki_protection_decorator(
7825d3
 
7825d3
             @wraps(fn)
7825d3
             def wrapper(*args: ArgsT.args, **kwargs: ArgsT.kwargs) -> RetT:
7825d3
-                locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = enabled
7825d3
+                sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = enabled
7825d3
                 return fn(*args, **kwargs)
7825d3
 
7825d3
             return wrapper
7825d3
diff --git a/trio/_core/_run.py b/trio/_core/_run.py
7825d3
index b5a4912..16657c0 100644
7825d3
--- a/trio/_core/_run.py
7825d3
+++ b/trio/_core/_run.py
7825d3
@@ -617,7 +617,7 @@ class CancelScope:
7825d3
 
7825d3
         # This inlines the enable_ki_protection decorator so we can fix
7825d3
         # f_locals *locally* below to avoid reference cycles
7825d3
-        locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+        sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
 
7825d3
         # Tracebacks show the 'raise' line below out of context, so let's give
7825d3
         # this variable a name that makes sense out of context.
7825d3
@@ -640,7 +640,7 @@ class CancelScope:
7825d3
                 # see test_cancel_scope_exit_doesnt_create_cyclic_garbage
7825d3
                 del remaining_error_after_cancel_scope, value, _, exc
7825d3
                 # deep magic to remove refs via f_locals
7825d3
-                locals()
7825d3
+                sys._getframe().f_locals
7825d3
                 # TODO: check if PEP558 changes the need for this call
7825d3
                 # https://github.com/python/cpython/pull/3640
7825d3
 
7825d3
@@ -2409,7 +2409,7 @@ def unrolled_run(
7825d3
     args: tuple[object, ...],
7825d3
     host_uses_signal_set_wakeup_fd: bool = False,
7825d3
 ) -> Generator[float, EventResult, None]:
7825d3
-    locals()[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
+    sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True
7825d3
     __tracebackhide__ = True
7825d3
 
7825d3
     try:
7825d3
diff --git a/trio/_tests/test_path.py b/trio/_tests/test_path.py
7825d3
index 3528053..dd3ec66 100644
7825d3
--- a/trio/_tests/test_path.py
7825d3
+++ b/trio/_tests/test_path.py
7825d3
@@ -120,7 +120,7 @@ async def test_async_method_signature(path: trio.Path) -> None:
7825d3
     assert path.resolve.__qualname__ == "Path.resolve"
7825d3
 
7825d3
     assert path.resolve.__doc__ is not None
7825d3
-    assert "pathlib.Path.resolve" in path.resolve.__doc__
7825d3
+    assert path.resolve.__qualname__ in path.resolve.__doc__
7825d3
 
7825d3
 
7825d3
 @pytest.mark.parametrize("method_name", ["is_dir", "is_file"])
7825d3
-- 
7825d3
2.44.0
7825d3