Nick Coghlan added the comment:
The relevant functions:
* PyRun_InteractiveLoopFlags:
https://github.com/python/cpython/blob/e8113f51a8bdf33188ee30a1c038a298329e7bfa/Python/pythonrun.c#L89
* PyRun_InteractiveOneObjectEx:
https://github.com/python/cpython/blob/e8113f51a8bdf33188ee30a1c038a298
Nick Coghlan added the comment:
The ``sys`` import gets cleared as well (accidentally omitted from the previous
comment):
```
>>> sys
Traceback (most recent call last):
File "", line 1, in
NameError: name 'sys' is not defined
```
--
___
Python
Nick Coghlan added the comment:
Additional info showing the module getting reset back to the state of a freshly
created module namespace:
```
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__',
'__package__', '__spec__']
>>> __builtins__
>>> import sys
>>> mod
New submission from Nick Coghlan :
While trying to create an example for a pickle bug discussion, I deliberately
dropped `__main__` out of sys.modules, and the REPL session lost all of its
runtime state.
Simplified reproducer:
```
>>> import sys
>>> mod = sys.modules[__name__]
>>> sys.modul