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

Function import_item

IPython/utils/importstring.py:12–41  ·  view source on GitHub ↗

Import and return ``bar`` given the string ``foo.bar``. Calling ``bar = import_item("foo.bar")`` is the functional equivalent of executing the code ``from foo import bar``. Parameters ---------- name : string The fully qualified name of the module/package being imported

(name: str)

Source from the content-addressed store, hash-verified

10
11
12def import_item(name: str) -> Any:
13 """Import and return ``bar`` given the string ``foo.bar``.
14
15 Calling ``bar = import_item("foo.bar")`` is the functional equivalent of
16 executing the code ``from foo import bar``.
17
18 Parameters
19 ----------
20 name : string
21 The fully qualified name of the module/package being imported.
22
23 Returns
24 -------
25 mod : module object
26 The module that was imported.
27 """
28
29 parts = name.rsplit(".", 1)
30 if len(parts) == 2:
31 # called with 'foo.bar....'
32 package, obj = parts
33 module = __import__(package, fromlist=[obj])
34 try:
35 pak = getattr(module, obj)
36 except AttributeError as e:
37 raise ImportError("No module named %s" % obj) from e
38 return pak
39 else:
40 # called with un-dotted string
41 return __import__(parts[0])

Callers 10

get_ipython_module_pathFunction · 0.90
init_llm_providerMethod · 0.90
_set_autosuggestionsMethod · 0.90
_import_appMethod · 0.90
_default_loop_runnerMethod · 0.90
_import_runnerMethod · 0.90
_auto_importMethod · 0.90
autoawaitMethod · 0.90
test_import_plainFunction · 0.90
test_import_nestedFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_import_plainFunction · 0.72
test_import_nestedFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…