From fb64db25f3a970feb6d96101ea00176d0e9ff648 Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Fri, 24 Jul 2026 22:39:57 +0800 Subject: [PATCH] gh-140326: disable the relative import in asyncio REPL (#140327) Co-authored-by: Kumar Aditya --- Lib/asyncio/__main__.py | 13 ++++++++----- .../2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py index 708fdd595971..cbb052630d71 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -212,11 +212,14 @@ if __name__ == '__main__': loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - repl_locals = {'asyncio': asyncio} - for key in {'__name__', '__package__', - '__loader__', '__spec__', - '__builtins__', '__file__'}: - repl_locals[key] = locals()[key] + repl_locals = { + 'asyncio': asyncio, + '__name__': __name__, + '__package__': None, + '__loader__': __loader__, + '__spec__': None, + '__builtins__': __builtins__, + } console = AsyncIOInteractiveConsole(repl_locals, loop) diff --git a/Misc/NEWS.d/next/Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst b/Misc/NEWS.d/next/Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst new file mode 100644 index 000000000000..07eea563ea5f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst @@ -0,0 +1,3 @@ +Fix the :mod:`asyncio` REPL namespace so that relative imports no longer +resolve against the :mod:`asyncio` package and ``__file__`` is no longer +set. -- 2.47.3