[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan
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

[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan
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

[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan
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

[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan
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