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

Function py_init_field_assignment

internal/cbm/extract_defs.c:7370–7399  ·  view source on GitHub ↗

`self.x: T = v` / `self.x = p` inside __init__ (self = its first parameter). */

Source from the content-addressed store, hash-verified

7368
7369/* `self.x: T = v` / `self.x = p` inside __init__ (self = its first parameter). */
7370static void py_init_field_assignment(CBMExtractCtx *ctx, const char *class_qn, TSNode assign,
7371 TSNode params, const char *self_name) {
7372 TSNode left = ts_node_child_by_field_name(assign, TS_FIELD("left"));
7373 if (ts_node_is_null(left) || strcmp(ts_node_type(left), "attribute") != 0) {
7374 return;
7375 }
7376 TSNode obj = ts_node_child_by_field_name(left, TS_FIELD("object"));
7377 TSNode attr = ts_node_child_by_field_name(left, TS_FIELD("attribute"));
7378 if (ts_node_is_null(obj) || ts_node_is_null(attr) ||
7379 strcmp(ts_node_type(obj), "identifier") != 0) {
7380 return;
7381 }
7382 char *obj_name = cbm_node_text(ctx->arena, obj, ctx->source);
7383 if (!obj_name || strcmp(obj_name, self_name) != 0) {
7384 return;
7385 }
7386 TSNode ann = ts_node_child_by_field_name(assign, TS_FIELD("type"));
7387 if (!ts_node_is_null(ann)) {
7388 py_push_field_type(ctx, class_qn, attr, cbm_node_text(ctx->arena, ann, ctx->source));
7389 return;
7390 }
7391 TSNode right = ts_node_child_by_field_name(assign, TS_FIELD("right"));
7392 if (ts_node_is_null(right) || strcmp(ts_node_type(right), "identifier") != 0) {
7393 return;
7394 }
7395 char *rhs = cbm_node_text(ctx->arena, right, ctx->source);
7396 if (rhs && strcmp(rhs, self_name) != 0) {
7397 py_push_field_type(ctx, class_qn, attr, py_init_param_annotation(ctx, params, rhs));
7398 }
7399}
7400
7401/* Every `self.x` field assignment in one __init__ body, nested blocks
7402 * included; nested functions, lambdas and classes have their own `self`. */

Callers 1

py_extract_init_fieldsFunction · 0.85

Calls 3

cbm_node_textFunction · 0.85
py_push_field_typeFunction · 0.85
py_init_param_annotationFunction · 0.85

Tested by

no test coverage detected