Skip to content

Commit c6a9eff

Browse files
miss-islingtonLocked-chess-officialkumaraditya303
authored
[3.15] gh-140326: disable the relative import in asyncio REPL (GH-140327) (#154628)
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 df66175 commit c6a9eff

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
@@ -212,11 +212,14 @@ def interrupt(self) -> None:
212212
loop = asyncio.new_event_loop()
213213
asyncio.set_event_loop(loop)
214214

215-
repl_locals = {'asyncio': asyncio}
216-
for key in {'__name__', '__package__',
217-
'__loader__', '__spec__',
218-
'__builtins__', '__file__'}:
219-
repl_locals[key] = locals()[key]
215+
repl_locals = {
216+
'asyncio': asyncio,
217+
'__name__': __name__,
218+
'__package__': None,
219+
'__loader__': __loader__,
220+
'__spec__': None,
221+
'__builtins__': __builtins__,
222+
}
220223

221224
console = AsyncIOInteractiveConsole(repl_locals, loop)
222225

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)