MCPcopy Index your code
hub / github.com/RustPython/RustPython / locate

Function locate

Lib/pydoc.py:1719–1736  ·  view source on GitHub ↗

Locate an object by name or dotted path, importing as necessary.

(path, forceload=0)

Source from the content-addressed store, hash-verified

1717 return type(thing).__name__
1718
1719def locate(path, forceload=0):
1720 """Locate an object by name or dotted path, importing as necessary."""
1721 parts = [part for part in path.split('.') if part]
1722 module, n = None, 0
1723 while n < len(parts):
1724 nextmodule = safeimport('.'.join(parts[:n+1]), forceload)
1725 if nextmodule: module, n = nextmodule, n + 1
1726 else: break
1727 if module:
1728 object = module
1729 else:
1730 object = builtins
1731 for part in parts[n:]:
1732 try:
1733 object = getattr(object, part)
1734 except AttributeError:
1735 return None
1736 return object
1737
1738# --------------------------------------- interactive interpreter interface
1739

Callers 2

resolveFunction · 0.85
html_getobjFunction · 0.85

Calls 5

lenFunction · 0.85
safeimportFunction · 0.85
getattrFunction · 0.85
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected