Resolve cross-file Python qualified class-method calls (``ClassName.method()``) to the class-qualified method node (#1446). The shared cross-file call pass drops every ``is_member_call`` because a bare method name (``log``) collides across the corpus and inflates god-nodes (#543/#12
(
per_file: list[dict],
all_nodes: list[dict],
all_edges: list[dict],
)
| 6671 | |
| 6672 | |
| 6673 | def _resolve_python_member_calls( |
| 6674 | per_file: list[dict], |
| 6675 | all_nodes: list[dict], |
| 6676 | all_edges: list[dict], |
| 6677 | ) -> None: |
| 6678 | """Resolve cross-file Python qualified class-method calls (``ClassName.method()``) |
| 6679 | to the class-qualified method node (#1446). |
| 6680 | |
| 6681 | The shared cross-file call pass drops every ``is_member_call`` because a bare |
| 6682 | method name (``log``) collides across the corpus and inflates god-nodes |
| 6683 | (#543/#1219). That guard is right for *instance* calls (``obj.method()``) but |
| 6684 | misses *class-qualified* calls (``ClassName.method()``), where the receiver is |
| 6685 | an explicitly-named class — an exact, unambiguous reference. This pass uses the |
| 6686 | receiver captured by the extractor, and when it is a capitalized name resolving |
| 6687 | to exactly one class node that owns the called method, emits an EXTRACTED |
| 6688 | ``calls`` edge. Purely additive (only member calls the shared pass skipped), |
| 6689 | with a single-definition god-node guard. |
| 6690 | |
| 6691 | Must run after id-disambiguation so node ids and caller_nids are final. |
| 6692 | """ |
| 6693 | def _key(label: str) -> str: |
| 6694 | return re.sub(r"[^a-zA-Z0-9]+", "", str(label)).lower() |
| 6695 | |
| 6696 | def _is_python_file(source_file: object) -> bool: |
| 6697 | # The effective suffix honours a `.graphifyrc` language override. Only a |
| 6698 | # suffix another extractor owns is rejected: an extensionless file (a |
| 6699 | # shebang script), an unknown suffix, or a raw call that names no file |
| 6700 | # passes, as before the gate. |
| 6701 | suffix = effective_suffix(str(source_file or "")) |
| 6702 | if suffix.lower() in (".py", ".pyi"): |
| 6703 | return True |
| 6704 | return suffix not in _DISPATCH and suffix.lower() not in _DISPATCH |
| 6705 | |
| 6706 | node_by_id: dict[str, dict] = {n.get("id"): n for n in all_nodes} |
| 6707 | |
| 6708 | # A class owns methods: it is the source of one or more `method` edges. Index |
| 6709 | # class label -> owning class node ids (len != 1 is the god-node guard), and |
| 6710 | # (class_node_id, method_key) -> method_node_id. |
| 6711 | class_def_nids: dict[str, list[str]] = {} |
| 6712 | method_index: dict[tuple[str, str], list[str]] = {} |
| 6713 | owner_of: dict[str, str] = {} |
| 6714 | for e in all_edges: |
| 6715 | if e.get("relation") != "method": |
| 6716 | continue |
| 6717 | src, tgt = e.get("source"), e.get("target") |
| 6718 | if src and tgt: |
| 6719 | owner_of[tgt] = src |
| 6720 | cnode = node_by_id.get(src) |
| 6721 | # Only Python classes are candidates: a Swift `Inner` must not trip the |
| 6722 | # single-definition guard for a Python `Inner`. |
| 6723 | if cnode is not None and _is_python_file(cnode.get("source_file")): |
| 6724 | class_def_nids.setdefault(_key(cnode.get("label", "")), []).append(src) |
| 6725 | tnode = node_by_id.get(tgt) |
| 6726 | if tnode is not None: |
| 6727 | slot = method_index.setdefault((src, _key(tnode.get("label", ""))), []) |
| 6728 | if tgt not in slot: |
| 6729 | slot.append(tgt) |
| 6730 |