MCPcopy Create free account
hub / github.com/ipython/ipython / init_sys_modules

Method init_sys_modules

IPython/core/interactiveshell.py:1324–1342  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1322 return user_module, user_ns
1323
1324 def init_sys_modules(self):
1325 # We need to insert into sys.modules something that looks like a
1326 # module but which accesses the IPython namespace, for shelve and
1327 # pickle to work interactively. Normally they rely on getting
1328 # everything out of __main__, but for embedding purposes each IPython
1329 # instance has its own private namespace, so we can't go shoving
1330 # everything into __main__.
1331
1332 # note, however, that we should only do this for non-embedded
1333 # ipythons, which really mimic the __main__.__dict__ with their own
1334 # namespace. Embedded instances, on the other hand, should not do
1335 # this because they need to manage the user local/global namespaces
1336 # only, but they live within a 'normal' __main__ (meaning, they
1337 # shouldn't overtake the execution environment of the script they're
1338 # embedded in).
1339
1340 # This is overridden in the InteractiveShellEmbed subclass to a no-op.
1341 main_name = self.user_module.__name__
1342 sys.modules[main_name] = self.user_module
1343
1344 def init_user_ns(self):
1345 """Initialize all user-visible namespaces to their minimum defaults.

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected