]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140326: disable the relative import in asyncio REPL (#140327)
authorLocked-chess-official <13140752715@163.com>
Fri, 24 Jul 2026 14:39:57 +0000 (22:39 +0800)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2026 14:39:57 +0000 (14:39 +0000)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Lib/asyncio/__main__.py
Misc/NEWS.d/next/Library/2025-10-19-17-34-07.gh-issue-140326.kZM0pV.rst [new file with mode: 0644]

index 708fdd595971e85432793d250c4582792696de0c..cbb052630d71ce9190bb5d0df32ae85db08f4f72 100644 (file)
@@ -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 (file)
index 0000000..07eea56
--- /dev/null
@@ -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.