Skip to content

Commit 8f1480d

Browse files
Explicitly set __package__ and __spec__ to None in REPL namespace
1 parent 83418f3 commit 8f1480d

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
@@ -190,11 +190,14 @@ def interrupt(self) -> None:
190190
loop = asyncio.new_event_loop()
191191
asyncio.set_event_loop(loop)
192192

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

199202
console = AsyncIOInteractiveConsole(repl_locals, loop)
200203

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)