Skip to content

Commit 1f0b70f

Browse files
miss-islingtonLocked-chess-officialkumaraditya303
authored
[3.14] gh-140326: disable the relative import in asyncio REPL (GH-140327) (#154627)
gh-140326: disable the relative import in asyncio REPL (GH-140327) (cherry picked from commit fb64db2) Co-authored-by: Locked-chess-official <13140752715@163.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parent 89be6f7 commit 1f0b70f

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/asyncio/__main__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,14 @@ def interrupt(self) -> None:
191191
loop = asyncio.new_event_loop()
192192
asyncio.set_event_loop(loop)
193193

194-
repl_locals = {'asyncio': asyncio}
195-
for key in {'__name__', '__package__',
196-
'__loader__', '__spec__',
197-
'__builtins__', '__file__'}:
198-
repl_locals[key] = locals()[key]
194+
repl_locals = {
195+
'asyncio': asyncio,
196+
'__name__': __name__,
197+
'__package__': None,
198+
'__loader__': __loader__,
199+
'__spec__': None,
200+
'__builtins__': __builtins__,
201+
}
199202

200203
console = AsyncIOInteractiveConsole(repl_locals, loop)
201204

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix the :mod:`asyncio` REPL namespace so that relative imports no longer
2+
resolve against the :mod:`asyncio` package and ``__file__`` is no longer
3+
set.

0 commit comments

Comments
 (0)