cocoindex-io/cocoindex · warning · DeprecationWarning
CodeSource.source is deprecated; use CodeSource.text
Error message
CodeSource.source is deprecated; use CodeSource.text
What it means
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.
Source
Thrown at python/cocoindex/ops/code.py:83
self = cls.__new__(cls)
self._src = raw
return self
@property
def text(self) -> str:
"""The source text."""
return self._src.text
@property
def language(self) -> str | None:
"""The language as given at construction (may be an alias/extension)."""
return self._src.language
@property
def source(self) -> str:
"""Deprecated alias of :attr:`text` (the name the removed ``CodeAst``
class used); use ``.text``."""
_warnings.warn(
"CodeSource.source is deprecated; use CodeSource.text",
DeprecationWarning,
stacklevel=2,
)
return self._src.text
def __repr__(self) -> str:
return f"CodeSource(language={self.language!r}, text_len={len(self.text)})"
@_dataclass(frozen=True, slots=True)
class CodeMatch:
"""A structural-match result: a matched node and its captured metavariables."""
kind: str
"""tree-sitter node kind of the matched node (e.g. ``function_definition``)."""
chunks: list[_chunk.Chunk]View on GitHub (pinned to e84aa99b32)
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.
Example fix
// before text = match.source // after text = match.source.text
Defensive patterns
Strategy: type-guard
Validate before calling
if isinstance(src, CodeSource) and not isinstance(getattr(type(src), 'source', None), property):
text = src.source # only safe if no deprecation shim Type guard
def get_source_text(src: CodeSource) -> str:
return src.text Try / catch
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="CodeSource.source is deprecated", category=DeprecationWarning)
text = legacy_api_source_field(obj) Prevention
- 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.
When it happens
Trigger: Accessing the .source property on a CodeSource instance obtained from CodePattern.match_source / match_code results.
Common situations: 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.
Understand the failure class
Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.
Related errors
- FileMatch.ast is deprecated; use FileMatch.source (and .text
- CodeAst is deprecated and now aliases CodeSource; use CodeSo
- use_mount() requires a ComponentSubpath when the function ha
- LiveComponent classes cannot be used with use_mount(). Use m
- mount() requires a ComponentSubpath when the function has no
AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08).
Data as JSON: /api/errors/80d0f36ccab264cc.
Report an issue: GitHub.