Skip to content

Commit fb64db2

Browse files
gh-140326: disable the relative import in asyncio REPL (#140327)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parent ad1cea6 commit fb64db2

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)