MCPcopy Index your code
hub / github.com/python/cpython / locate

Function locate

Lib/pydoc.py:1673–1690  ·  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

1671 return type(thing).__name__
1672
1673def locate(path, forceload=0):
1674 """Locate an object by name or dotted path, importing as necessary."""
1675 parts = [part for part in path.split('.') if part]
1676 module, n = None, 0
1677 while n < len(parts):
1678 nextmodule = safeimport('.'.join(parts[:n+1]), forceload)
1679 if nextmodule: module, n = nextmodule, n + 1
1680 else: break
1681 if module:
1682 object = module
1683 else:
1684 object = builtins
1685 for part in parts[n:]:
1686 try:
1687 object = getattr(object, part)
1688 except AttributeError:
1689 return None
1690 return object
1691
1692# --------------------------------------- interactive interpreter interface
1693

Callers 2

resolveFunction · 0.85
html_getobjFunction · 0.85

Calls 3

safeimportFunction · 0.85
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…