From ec6fbfcb8c7e152bba1cbad0135806e721e747e8 Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Sun, 19 Oct 2025 17:34:40 +0800 Subject: [PATCH 1/2] remove __package__, __file__, __spec__ in locals() --- Lib/asyncio/__main__.py | 6 +++--- .../Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst | 1 + 2 files changed, 4 insertions(+), 3 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 708fdd595971e85..da2223af30ccb65 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -213,9 +213,9 @@ def interrupt(self) -> None: asyncio.set_event_loop(loop) repl_locals = {'asyncio': asyncio} - for key in {'__name__', '__package__', - '__loader__', '__spec__', - '__builtins__', '__file__'}: + for key in {'__name__', + '__loader__', + '__builtins__'}: repl_locals[key] = locals()[key] 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 000000000000000..aec5ad27a47cd2f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst @@ -0,0 +1 @@ +Disable relative import in asyncio repl From 49217b5d88b9291cbd59defd3bf0b3d9c5d63006 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Fri, 24 Jul 2026 17:45:15 +0530 Subject: [PATCH 2/2] Explicitly set __package__ and __spec__ to None in REPL namespace --- Lib/asyncio/__main__.py | 13 ++++++++----- .../2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py index da2223af30ccb65..cbb052630d71ce9 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -212,11 +212,14 @@ def interrupt(self) -> None: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - repl_locals = {'asyncio': asyncio} - for key in {'__name__', - '__loader__', - '__builtins__'}: - 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 index aec5ad27a47cd2f..07eea563ea5fbc0 100644 --- 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 @@ -1 +1,3 @@ -Disable relative import in asyncio repl +Fix the :mod:`asyncio` REPL namespace so that relative imports no longer +resolve against the :mod:`asyncio` package and ``__file__`` is no longer +set.