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

Function py_ns_assignment

internal/cbm/extract_imports.c:673–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671}
672
673static bool py_ns_assignment(PyNamespaceBuilder *b, TSNode node) {
674 TSNode left = ts_node_child_by_field_name(node, TS_FIELD("left"));
675 TSNode right = ts_node_child_by_field_name(node, TS_FIELD("right"));
676 TSNode annotation = ts_node_child_by_field_name(node, TS_FIELD("type"));
677 const char *name = py_ns_name(b, left, false);
678 if (!name)
679 return false;
680 if (!py_ns_safe_expr(b, right, 0) || !py_ns_safe_expr(b, annotation, 0)) {
681 if (!py_ns_unknown(b, CBM_PY_NS_REASON_EFFECT))
682 return false;
683 }
684 if (ts_node_is_null(right))
685 return true; /* annotation alone does not bind the target */
686 bool augmented = strcmp(ts_node_type(node), "augmented_assignment") == 0;
687 if (strcmp(name, "__all__") != 0) {
688 if (augmented)
689 return py_ns_unknown(b, CBM_PY_NS_REASON_UNSUPPORTED);
690 return py_ns_push(b, (CBMPyNamespaceFact){.kind = CBM_PY_NS_SHADOW,
691 .local_name = name,
692 .reason = CBM_PY_NS_REASON_VALUE});
693 }
694 CBMPyNamespaceFact fact = {.kind = augmented ? CBM_PY_NS_ALL_APPEND : CBM_PY_NS_ALL_SET};
695 bool plus = true;
696 if (augmented) {
697 const char *op = NULL;
698 size_t len = 0;
699 plus = py_ns_slice(b, ts_node_child_by_field_name(node, TS_FIELD("operator")), &op, &len) &&
700 len == 2 && memcmp(op, "+=", 2) == 0;
701 }
702 if (plus && py_ns_all_literal(b, right, &fact))
703 return py_ns_push(b, fact);
704 return py_ns_push(
705 b, (CBMPyNamespaceFact){.kind = CBM_PY_NS_ALL_UNKNOWN, .reason = CBM_PY_NS_REASON_VALUE});
706}
707
708static bool py_ns_delete(PyNamespaceBuilder *b, TSNode node, int depth) {
709 if (depth > 2)

Callers 1

py_ns_statementFunction · 0.85

Calls 6

py_ns_nameFunction · 0.85
py_ns_safe_exprFunction · 0.85
py_ns_unknownFunction · 0.85
py_ns_pushFunction · 0.85
py_ns_sliceFunction · 0.85
py_ns_all_literalFunction · 0.85

Tested by

no test coverage detected