Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/evidently/descriptors/text_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ def exact_match(self, text: str, items: List[str]) -> bool:


class TextMatch(Descriptor):
"""
# The docstring contains a regex example with `\b\d{3}-\d{3}-\d{4}\b`. The
# `r"..."` prefix only marks the *example* literal as raw — the docstring
# itself still parses every backslash, so `\d` triggers
# `SyntaxWarning: invalid escape sequence '\d'` on Python 3.12+. Marking the
# docstring itself raw silences the warning without changing rendered help.
r"""
Unified text matching descriptor that handles all word/text matching scenarios.

This descriptor replaces multiple legacy text matching features with a single,
Expand Down
17 changes: 17 additions & 0 deletions tests/future/descriptors/test_text_match.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import py_compile
import warnings

import pandas as pd
import pytest

from evidently.core.datasets import Dataset
from evidently.descriptors import TextMatch
import evidently.descriptors.text_match as text_match_module


def test_text_match_module_compiles_without_syntax_warning(tmp_path):
# Regression: the TextMatch docstring contains an `r"\b\d{3}-..."` regex
# example, but the docstring itself wasn't raw, so `\d` triggered
# `SyntaxWarning: invalid escape sequence '\d'` on Python 3.12+.
# py_compile surfaces SyntaxWarnings as PyCompileErrors when warnings are
# promoted to errors, so this is a reliable check that doesn't depend on
# whether the module is already cached / imported elsewhere.
source_path = text_match_module.__file__
with warnings.catch_warnings():
warnings.simplefilter("error", SyntaxWarning)
py_compile.compile(source_path, cfile=str(tmp_path / "out.pyc"), doraise=True)


@pytest.fixture
Expand Down