MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / python_receiver_is_exempt

Function python_receiver_is_exempt

internal/cbm/extract_calls.c:3733–3778  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3731}
3732
3733static bool python_receiver_is_exempt(CBMExtractCtx *ctx, TSNode receiver) {
3734 if (ts_node_is_null(receiver)) {
3735 return false;
3736 }
3737
3738 /* super().m() — the receiver is a call node whose function is `super`. */
3739 if (strcmp(ts_node_type(receiver), "call") == 0) {
3740 TSNode fn = ts_node_child_by_field_name(receiver, TS_FIELD("function"));
3741 if (!ts_node_is_null(fn) && strcmp(ts_node_type(fn), "identifier") == 0) {
3742 char *name = cbm_node_text(ctx->arena, fn, ctx->source);
3743 return name && strcmp(name, "super") == 0;
3744 }
3745 return false;
3746 }
3747
3748 /* Walk an attribute chain down to its root identifier: for `pkg.sub.fn()`
3749 * the receiver is `pkg.sub`, whose root is `pkg` — the name an import binds. */
3750 bool direct_identifier = strcmp(ts_node_type(receiver), "identifier") == 0;
3751 TSNode root = receiver;
3752 while (!ts_node_is_null(root) && strcmp(ts_node_type(root), "attribute") == 0) {
3753 root = ts_node_child_by_field_name(root, TS_FIELD("object"));
3754 }
3755 if (ts_node_is_null(root) || strcmp(ts_node_type(root), "identifier") != 0) {
3756 return false;
3757 }
3758
3759 char *name = cbm_node_text(ctx->arena, root, ctx->source);
3760 if (!name) {
3761 return false;
3762 }
3763 /* self/cls only as a DIRECT receiver: `self.m()` is class-local, but
3764 * `self.client.m()` has receiver `self.client` of unknown type. */
3765 if (direct_identifier && (strcmp(name, "self") == 0 || strcmp(name, "cls") == 0)) {
3766 return true;
3767 }
3768 /* Import-bound root, incl. aliases (`import tools as toolkit` binds
3769 * local_name "toolkit"). Per-file scan: imports.count is a file-local
3770 * number (tens), never the corpus, so this stays O(file), not O(corpus). */
3771 for (int i = 0; i < ctx->result->imports.count; i++) {
3772 const char *local_name = ctx->result->imports.items[i].local_name;
3773 if (local_name && strcmp(local_name, name) == 0) {
3774 return true;
3775 }
3776 }
3777 return false;
3778}
3779
3780/* Name bound by one Python parameter node, or NULL when the shape binds none.
3781 * Covers every binding form a `parameters` / `lambda_parameters` list produces:

Callers 1

handle_callsFunction · 0.85

Calls 1

cbm_node_textFunction · 0.85

Tested by

no test coverage detected