Return (imported name, local binding) pairs from a Python import node.
(node, source: bytes)
| 902 | # ── Import handlers ─────────────────────────────────────────────────────────── |
| 903 | |
| 904 | def _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 | |
| 930 | def _missing_relative_module_name(attempted: Path, root: Path, raw: str) -> str: |
no test coverage detected