{"record":{"id":"cdf4d49fc4ad03d7","repo":"cocoindex-io/cocoindex","slug":"codeast-is-deprecated-and-now-aliases-codesource","errorCode":null,"errorMessage":"CodeAst is deprecated and now aliases CodeSource; use CodeSource with CodePattern.match_source / match_code, RecursiveSplitter.split, and index_terms","messagePattern":"CodeAst is deprecated and now aliases CodeSource; use CodeSource with CodePattern\\.match_source / match_code, RecursiveSplitter\\.split, and index_terms","errorType":"console","errorClass":"DeprecationWarning","httpStatus":null,"severity":"warning","filePath":"python/cocoindex/ops/code.py","lineNumber":330,"sourceCode":"            summary=seg.summary,\n            rendered_start=seg.rendered_start,\n            rendered_end=seg.rendered_end,\n        )\n        for seg in raw.segments\n    ]\n    return _view.SourceView(text=raw.text, segments=segments)\n\n\ndef __getattr__(name: str) -> _typing.Any:\n    # Deprecated alias for the removed ``CodeAst`` class, so annotations and\n    # ``isinstance`` checks in older callers keep working. ``CodeSource`` is\n    # the single handle now; note its constructor is lazy and tolerant where\n    # ``CodeAst``'s was eager and raising, and the old ``.matches`` / ``.split``\n    # / ``.index_terms`` methods live on the consumers instead\n    # (``CodePattern.match_source`` / ``match_code``, ``RecursiveSplitter.split``,\n    # ``index_terms``).\n    if name == \"CodeAst\":\n        _warnings.warn(\n            \"CodeAst is deprecated and now aliases CodeSource; use CodeSource \"\n            \"with CodePattern.match_source / match_code, RecursiveSplitter.split, \"\n            \"and index_terms\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        return CodeSource\n    raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n","sourceCodeStart":312,"sourceCodeEnd":339,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/ops/code.py#L312-L339","documentation":"The module-level name CodeAst has been removed/renamed to CodeSource; a module __getattr__ still resolves CodeAst to CodeSource but emits a DeprecationWarning. Its old eager constructor semantics and .matches/.split/.index_terms methods are gone — those operations now live on consumers (CodePattern.match_source/match_code, RecursiveSplitter.split, index_terms).","triggerScenarios":"Importing or referencing ops.code.CodeAst (e.g. `from cocoindex.ops.code import CodeAst` or attribute access), which hits the module __getattr__ path.","commonSituations":"Legacy code and examples written before the CodeAst→CodeSource refactor; upgrades surface the DeprecationWarning and may then fail where old methods (.matches, .split on the handle) are called.","solutions":["Replace CodeAst with CodeSource in imports and annotations.","Move parse-and-match calls to CodePattern.match_source / match_code.","Replace old handle.split calls with RecursiveSplitter.split and indexing-term usage with index_terms.","Note CodeSource's constructor is lazy and tolerant where CodeAst's was eager and raising; remove try/except around construction that relied on eager validation."],"exampleFix":"// before\nfrom cocoindex.ops.code import CodeAst\nast = CodeAst(text)\nmatches = ast.matches(pattern)\n// after\nfrom cocoindex.ops.code import CodePattern, CodeSource\nsrc = CodeSource(text)\nmatches = pattern.match_source(src)","handlingStrategy":"type-guard","validationCode":"import cocoindex.ops.code as code_ops\nif hasattr(code_ops, \"CodeAst\"):\n    import warnings\n    warnings.warn(\"CodeAst still referenced; migrate to CodeSource\", DeprecationWarning)","typeGuard":"def uses_removed_codeast(module: object) -> bool:\n    return getattr(module, \"CodeAst\", None) is not None","tryCatchPattern":"import warnings\nwith warnings.catch_warnings():\n    warnings.filterwarnings(\"ignore\", message=\"CodeAst is deprecated\", category=DeprecationWarning)\n    CodeSource = code_ops.CodeAst  # transitional shim only","preventionTips":["Import CodeSource, never CodeAst, in new code.","Use CodePattern.match_source / match_code instead of instance .matches.","Use RecursiveSplitter.split and index_terms for splitting/indexing instead of handle methods.","Enable -W error::DeprecationWarning in test runs to catch removed-name usage immediately."],"tags":["deprecation","python","api-migration","rename"],"backgroundTag":"deprecated-api-usage","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}