MCPcopy Index your code
hub / github.com/ipython/ipython / import_submodule

Function import_submodule

IPython/lib/deepreload.py:164–191  ·  view source on GitHub ↗

m = import_submodule(mod, subname, fullname)

(mod, subname, fullname)

Source from the content-addressed store, hash-verified

162found_now = {}
163
164def import_submodule(mod, subname, fullname):
165 """m = import_submodule(mod, subname, fullname)"""
166 # Require:
167 # if mod == None: subname == fullname
168 # else: mod.__name__ + "." + subname == fullname
169
170 global found_now
171 if fullname in found_now and fullname in sys.modules:
172 m = sys.modules[fullname]
173 else:
174 print('Reloading', fullname)
175 found_now[fullname] = 1
176 oldm = sys.modules.get(fullname, None)
177 try:
178 if oldm is not None:
179 m = importlib.reload(oldm)
180 else:
181 m = importlib.import_module(subname, mod)
182 except:
183 # load_module probably removed name from modules because of
184 # the error. Put back the original module object.
185 if oldm:
186 sys.modules[fullname] = oldm
187 raise
188
189 add_submodule(mod, m, fullname, subname)
190
191 return m
192
193def add_submodule(mod, submod, fullname, subname):
194 """mod.{subname} = submod"""

Callers 2

load_nextFunction · 0.85
ensure_fromlistFunction · 0.85

Calls 3

add_submoduleFunction · 0.85
getMethod · 0.80
reloadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…