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

Function _get_external

IPython/core/guarded_eval.py:127–147  ·  view source on GitHub ↗

Get value from external module given a dotted access path. Only gets value if the module is already imported. Raises: * `KeyError` if module is removed not found, and * `AttributeError` if access path does not match an exported object

(module_name: str, access_path: Sequence[str])

Source from the content-addressed store, hash-verified

125
126
127def _get_external(module_name: str, access_path: Sequence[str]):
128 """Get value from external module given a dotted access path.
129
130 Only gets value if the module is already imported.
131
132 Raises:
133 * `KeyError` if module is removed not found, and
134 * `AttributeError` if access path does not match an exported object
135 """
136 try:
137 member_type = sys.modules[module_name]
138 # standard module
139 for attr in access_path:
140 member_type = getattr(member_type, attr)
141 return member_type
142 except (KeyError, AttributeError):
143 # handle modules in namespace packages
144 module_path = ".".join([module_name, *access_path])
145 if module_path in sys.modules:
146 return sys.modules[module_path]
147 raise
148
149
150def _has_original_dunder_external(

Callers 2

can_get_attrMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…