Skip to content

Commit 5e24f65

Browse files
committed
Set a__main__ module and set interpreter's namespace to that module's dict.
This fixes issue #68.
1 parent 33d695a commit 5e24f65

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

bpython/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from itertools import takewhile
4242
from locale import LC_ALL, getpreferredencoding, setlocale
4343
from optparse import OptionParser
44+
from types import ModuleType
4445

4546
# These are used for syntax hilighting.
4647
from pygments import format
@@ -1512,7 +1513,8 @@ def main_curses(scr, args, interactive=True, locals_=None):
15121513
main_win, statusbar = init_wins(scr, cols)
15131514

15141515
if locals_ is None:
1515-
locals_ = dict(__name__='__main__', __doc__=None)
1516+
sys.modules['__main__'] = ModuleType('__main__')
1517+
locals_ = sys.modules['__main__'].__dict__
15161518
interpreter = Interpreter(locals_, getpreferredencoding())
15171519

15181520
repl = CLIRepl(main_win, interpreter, statusbar, idle)

0 commit comments

Comments
 (0)