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

Function _overload_pairs

graphify/interface_dispatch.py:229–265  ·  view source on GitHub ↗

Pair an interface's methods of one name with an implementer's. One of each pairs up as always. Otherwise (C# overloads, #4584) each interface method pairs with the one implementer method of the same declared signature, else of the same parameter count among those no signature claime

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

Source from the content-addressed store, hash-verified

227
228
229def _overload_pairs(
230 declared: set[str], candidates: set[str], node_by_id: dict,
231 *, match_arity: bool = False,
232) -> list[tuple[str, str]]:
233 """Pair an interface's methods of one name with an implementer's.
234
235 One of each pairs up as always. Otherwise (C# overloads, #4584) each
236 interface method pairs with the one implementer method of the same declared
237 signature, else of the same parameter count among those no signature
238 claimed; no unique match, no edge. An implementer method takes at most one
239 interface method, so an overload implemented on a base class is not pinned
240 on a sibling of the same count. With ``match_arity``, the one-of-each pair
241 also needs the same recorded parameter count.
242 """
243 def _meta(nid: str) -> dict:
244 meta = (node_by_id.get(nid) or {}).get("metadata")
245 return meta if isinstance(meta, dict) else {}
246
247 if len(declared) == 1 and len(candidates) == 1:
248 source, target = next(iter(declared)), next(iter(candidates))
249 if match_arity and _meta(source).get("arity") != _meta(target).get("arity"):
250 return []
251 return [(source, target)]
252
253 pairs: dict[str, str] = {}
254 for key in ("signature", "arity"):
255 taken = set(pairs.values())
256 for source in sorted(declared):
257 want = _meta(source).get(key)
258 if source in pairs or want is None:
259 continue
260 hits = [c for c in candidates if c not in taken and _meta(c).get(key) == want]
261 if len(hits) == 1:
262 pairs[source] = hits[0]
263 # Two interface methods on one implementer method: neither is certain.
264 targets = list(pairs.values())
265 return [(s, t) for s, t in pairs.items() if targets.count(t) == 1]

Callers 1

_implementing_pairsFunction · 0.85

Calls 3

_metaFunction · 0.85
getMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected