Skip to content

Commit 49217b5

Browse files
Explicitly set __package__ and __spec__ to None in REPL namespace
1 parent ec6fbfc commit 49217b5

2 files changed

Lines changed: 11 additions & 6 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__',
217-
'__loader__',
218-
'__builtins__'}:
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Disable relative import in asyncio repl
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)