{"record":{"id":"80d0f36ccab264cc","repo":"cocoindex-io/cocoindex","slug":"codesource-source-is-deprecated-use-codesource-te","errorCode":null,"errorMessage":"CodeSource.source is deprecated; use CodeSource.text","messagePattern":"CodeSource\\.source is deprecated; use CodeSource\\.text","errorType":"console","errorClass":"DeprecationWarning","httpStatus":null,"severity":"warning","filePath":"python/cocoindex/ops/code.py","lineNumber":83,"sourceCode":"        self = cls.__new__(cls)\n        self._src = raw\n        return self\n\n    @property\n    def text(self) -> str:\n        \"\"\"The source text.\"\"\"\n        return self._src.text\n\n    @property\n    def language(self) -> str | None:\n        \"\"\"The language as given at construction (may be an alias/extension).\"\"\"\n        return self._src.language\n\n    @property\n    def source(self) -> str:\n        \"\"\"Deprecated alias of :attr:`text` (the name the removed ``CodeAst``\n        class used); use ``.text``.\"\"\"\n        _warnings.warn(\n            \"CodeSource.source is deprecated; use CodeSource.text\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        return self._src.text\n\n    def __repr__(self) -> str:\n        return f\"CodeSource(language={self.language!r}, text_len={len(self.text)})\"\n\n\n@_dataclass(frozen=True, slots=True)\nclass CodeMatch:\n    \"\"\"A structural-match result: a matched node and its captured metavariables.\"\"\"\n\n    kind: str\n    \"\"\"tree-sitter node kind of the matched node (e.g. ``function_definition``).\"\"\"\n\n    chunks: list[_chunk.Chunk]","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/ops/code.py#L65-L101","documentation":"CodeSource.source is a deprecated property alias for CodeSource.text, kept because the removed CodeAst class used that name. Reading it emits a DeprecationWarning and returns the same text; it will eventually be removed.","triggerScenarios":"Accessing the .source property on a CodeSource instance obtained from CodePattern.match_source / match_code results.","commonSituations":"Code written against the old CodeAst API (where the parsed object exposed .source) that now runs against CodeSource and trips the deprecation warning after an upgrade.","solutions":["Replace code_source.source with code_source.text.","Use .language only for the language attribute; the file content lives on .text.","Search your codebase for '\\.source' on CodeSource/CodeAst results and migrate all call sites."],"exampleFix":"// before\ntext = match.source\n// after\ntext = match.source.text","handlingStrategy":"type-guard","validationCode":"if isinstance(src, CodeSource) and not isinstance(getattr(type(src), 'source', None), property):\n    text = src.source  # only safe if no deprecation shim","typeGuard":"def get_source_text(src: CodeSource) -> str:\n    return src.text","tryCatchPattern":"import warnings\nwith warnings.catch_warnings():\n    warnings.filterwarnings(\"ignore\", message=\"CodeSource.source is deprecated\", category=DeprecationWarning)\n    text = legacy_api_source_field(obj)","preventionTips":["Always use .text for file content on CodeSource.","Run tests with -W error::DeprecationWarning to catch renamed attributes early.","Check the class docstring for 'Deprecated alias' notes after upgrades."],"tags":["deprecation","python","api-migration","text-processing"],"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"}