cocoindex-io/cocoindex · warning · DeprecationWarning
FileMatch.ast is deprecated; use FileMatch.source (and .text
Error message
FileMatch.ast is deprecated; use FileMatch.source (and .text for the file content)
What it means
FileMatch.ast is a deprecated property alias for FileMatch.source, kept because the field was named .ast when the removed CodeAst class existed. Accessing it warns with DeprecationWarning and returns the CodeSource; the file content is on .source.text.
Source
Thrown at python/cocoindex/ops/code.py:198
"""The result of :meth:`CodePattern.match_file`: the parsed source and the
matches found in one file. The file content is ``file_match.source.text``."""
path: str
"""The path that was matched."""
source: CodeSource
"""The parsed source (its AST is already cached — reuse it to split or match
more patterns without re-parsing)."""
matches: list[CodeMatch]
"""The matches found (always at least one — ``match_file`` returns ``None``
when there are none)."""
@property
def ast(self) -> CodeSource:
"""Deprecated alias of :attr:`source` (the field's name when it held the
removed ``CodeAst`` class); use ``.source``."""
_warnings.warn(
"FileMatch.ast is deprecated; use FileMatch.source "
"(and .text for the file content)",
DeprecationWarning,
stacklevel=2,
)
return self.source
def match_code(
pattern: str, source: "str | CodeSource", language: str | None = None
) -> list[CodeMatch]:
r"""One-shot: match ``pattern`` against ``source`` and return all matches.
``source`` is a ``str`` (with ``language`` required) or a :class:`CodeSource`
(whose cached parse is reused; ``language`` must be omitted). Prefer a
:class:`CodePattern` when matching the same pattern across many sources —
this recompiles the pattern per call."""
if isinstance(source, CodeSource):View on GitHub (pinned to e84aa99b32)
Solutions
- Replace file_match.ast with file_match.source.
- Read the file content via file_match.source.text instead of assuming .ast holds parsed AST data.
- Grep for '.ast' on match results and migrate all usages.
Example fix
// before src = m.ast text = m.ast.text // after src = m.source text = m.source.text
Defensive patterns
Strategy: type-guard
Type guard
def match_text(m: FileMatch) -> str:
return m.source.text Try / catch
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="FileMatch.ast is deprecated", category=DeprecationWarning)
src = legacy_match_field(m) Prevention
- Use FileMatch.source (and .source.text) exclusively in new code.
- Enable DeprecationWarning-as-error in CI to catch alias usage.
- After upgrading, grep for '.ast' on code-match results and migrate.
When it happens
Trigger: Accessing the .ast property on a FileMatch returned by CodePattern.match_source / match_code.
Common situations: Old code iterating code-pattern matches via match.ast that predates the CodeAst→CodeSource rename, triggering the DeprecationWarning after upgrading.
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
- CodeSource.source is deprecated; use CodeSource.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/167a2461c18cc3d3.
Report an issue: GitHub.