From: Locked-chess-official <13140752715@163.com> Date: Fri, 24 Jul 2026 14:39:57 +0000 (+0800) Subject: gh-140326: disable the relative import in asyncio REPL (#140327) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fb64db25f3a970feb6d96101ea00176d0e9ff648;p=thirdparty%2FPython%2Fcpython.git gh-140326: disable the relative import in asyncio REPL (#140327) Co-authored-by: Kumar Aditya --- 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.