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

Nick Coghlan report at bugs.python.org
Thu Apr 18 21:13:30 EDT 2019


Nick Coghlan <ncoghlan at gmail.com> 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__
<module 'builtins' (built-in)>
>>> import sys
>>> mod = sys.modules[__name__]
>>> sys.modules[__name__] = object()
>>> __builtins__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__builtins__' is not defined
>>> __annotations__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__annotations__' is not defined
>>> __doc__
>>> __loader__
>>> __name__
'__main__'
>>> __package__
>>> __spec__
>>> mod
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'mod' is not defined
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36665>
_______________________________________


More information about the Python-bugs-list mailing list