MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _python_import_bindings

Function _python_import_bindings

graphify/extract.py:904–927  ·  view source on GitHub ↗

Return (imported name, local binding) pairs from a Python import node.

(node, source: bytes)

Source from the content-addressed store, hash-verified

902# ── Import handlers ───────────────────────────────────────────────────────────
903
904def _python_import_bindings(node, source: bytes) -> list[tuple[str, str]]:
905 """Return (imported name, local binding) pairs from a Python import node."""
906 bindings: list[tuple[str, str]] = []
907 past_import = False
908 for child in node.children:
909 if child.type == "import":
910 past_import = True
911 continue
912 if not past_import:
913 continue
914 if child.type == "dotted_name":
915 imported = _read_text(child, source)
916 bindings.append((imported, imported.split(".")[-1]))
917 elif child.type == "aliased_import":
918 name_node = child.child_by_field_name("name")
919 alias_node = child.child_by_field_name("alias")
920 if name_node is None:
921 continue
922 imported = _read_text(name_node, source)
923 local = _read_text(alias_node, source) if alias_node is not None else imported.split(".")[-1]
924 bindings.append((imported, local))
925 elif child.type == "wildcard_import":
926 bindings.append(("*", "*"))
927 return bindings
928
929
930def _missing_relative_module_name(attempted: Path, root: Path, raw: str) -> str:

Callers 1

_import_pythonFunction · 0.85

Calls 1

_read_textFunction · 0.90

Tested by

no test coverage detected