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

Function _implementing_pairs

graphify/interface_dispatch.py:202–226  ·  view source on GitHub ↗

Pair an interface's methods of one name with the implementer's members. A C# explicit implementation (``int IA.Get()``) implements a member of its own interface and wins over a public ``Get()`` for it; it never implements another interface. So the interface methods are paired with the e

(
    declared: set[str], candidates: set[str], interface_name: str, node_by_id: dict,
    *, match_arity: bool = False,
)

Source from the content-addressed store, hash-verified

200
201
202def _implementing_pairs(
203 declared: set[str], candidates: set[str], interface_name: str, node_by_id: dict,
204 *, match_arity: bool = False,
205) -> list[tuple[str, str]]:
206 """Pair an interface's methods of one name with the implementer's members.
207
208 A C# explicit implementation (``int IA.Get()``) implements a member of its
209 own interface and wins over a public ``Get()`` for it; it never implements
210 another interface. So the interface methods are paired with the explicit
211 implementations of this interface first, and only the ones left over with
212 the ordinary members (``int IA.Get()`` explicit beside a public
213 ``int Get(int)`` implementing ``IA.Get(int)``). Languages without explicit
214 implementations see a single ordinary pass.
215 """
216 def _explicit(nid: str) -> str | None:
217 meta = (node_by_id.get(nid) or {}).get("metadata")
218 return meta.get("explicit_interface") if isinstance(meta, dict) else None
219
220 own = {c for c in candidates if _explicit(c) == interface_name}
221 ordinary = {c for c in candidates if not _explicit(c)}
222 pairs = _overload_pairs(declared, own, node_by_id, match_arity=match_arity) if own else []
223 left = declared - {source for source, _ in pairs}
224 if left and ordinary:
225 pairs += _overload_pairs(left, ordinary, node_by_id, match_arity=match_arity)
226 return pairs
227
228
229def _overload_pairs(

Callers 1

Calls 2

_overload_pairsFunction · 0.85
_explicitFunction · 0.70

Tested by

no test coverage detected